• Home
  • Shell
    • Emacs
    • Perl
    • screen
    • sed
  • Ubuntu
    • VNC
  • Web Development
    • Javascript
    • Joomla
    • MySQL
    • osTicket
  • Windows
    • Gimp

osTicket> Transfer/Assign with no comment

Oct26
2010
Written by Scott Rowley

Today we are going to show you how to get rid of the annoying requirement of adding a comment to a ticket transfer or assignment…

For the “Assign to Staff” section you can comment out the following line from

scp/tickets.php

$fields['assign_message'] = array('type'=>'text', 'required'=>1, 'error'=>'Message required');

like so:

//$fields['assign_message'] = array('type'=>'text', 'required'=>1, 'error'=>'Message required');

For assign to department you’ll need:
scp/tickets.php

$fields['message'] = array('type'=>'text', 'required'=>1, 'error'=>'Note/Message required');

Like so:

//$fields['message'] = array('type'=>'text', 'required'=>1, 'error'=>'Note/Message required');

Then if you want to let people know that it is not required you can go into

include/staff/viewticket.inc.php
Find (for assign to staff):

<span >Comments/message for assignee. (<i>Saved as internal note</i>)
<font class="error"> *<?=$errors['assign_message']?></font></span>

And remove:

<font class="error"> *<?=$errors['assign_message']?></font>

Find (for department transfer):

<span >Comments/Reasons for the transfer. (<i>Internal note</i>)
<font class="error"> *<?=$errors['message']?></font></span>

Remove:

<font class="error"> *<?=$errors['message']?></font>

Now comments are no longer required to be present before assigning or transferring a ticket — and users are aware that it is not required.

Posted in osTicket - Tagged assign, comment, mod, modification, osTicket, ticket, transfer

osTicket> Mass ‘Ban & Delete’

Oct26
2010
Written by Scott Rowley

Ok, people…careful with this one!

This is for if you would like to allow for mass ban & delete from the Tickets tab.
First you need to add a new button to the main page.

include/staff/tickets.inc.php

<input class="button" type="submit" name="banDelete" value="Ban & Delete"
onClick=' return confirm("Are you ABSOLUTLEY CERTAIN this was spam?");'>

Then we need to add the functionality. Its easier here to replace a larger chunk so…

scp/tickets.php
Replace

if(!$errors) {
$count=count($_POST['tids']);
if(isset($_POST['reopen'])){
$i=0;
foreach($_POST['tids'] as $k=>$v) {
$t = new Ticket($v);
if($t && @$t->reopen()) $i++;
}
$msg="$i of $count selected tickets reopened";
}elseif(isset($_POST['close'])){
$i=0;
foreach($_POST['tids'] as $k=>$v) {
$t = new Ticket($v);
if($t && @$t->close()) $i++;
}
$msg="$i of $count selected tickets closed";
}elseif(isset($_POST['overdue'])){
$i=0;
foreach($_POST['tids'] as $k=>$v) {
$t = new Ticket($v);
if($t && !$t->isoverdue())
if($t->markOverdue()) $i++;
}
$msg="$i of $count selected tickets marked overdue";
}elseif(isset($_POST['delete'])){
$i=0;
foreach($_POST['tids'] as $k=>$v) {
$t = new Ticket($v);
if($t && @$t->delete()) $i++;
}
$msg="$i of $count selected tickets deleted";
}
}
break;

With

if(!$errors) {
$count=count($_POST['tids']);
if(isset($_POST['reopen'])){
$i=0;
foreach($_POST['tids'] as $k=>$v) {
$t = new Ticket($v);
if($t && @$t->reopen()) $i++;
}
$msg="$i of $count selected tickets reopened";
}elseif(isset($_POST['close'])){
$i=0;
foreach($_POST['tids'] as $k=>$v) {
$t = new Ticket($v);
if($t && @$t->close()) $i++;
}
$msg="$i of $count selected tickets closed";
}elseif(isset($_POST['overdue'])){
$i=0;
foreach($_POST['tids'] as $k=>$v) {
$t = new Ticket($v);
if($t && !$t->isoverdue())
if($t->markOverdue()) $i++;
}
$msg="$i of $count selected tickets marked overdue";
}elseif(isset($_POST['delete'])){
$i=0;
foreach($_POST['tids'] as $k=>$v) {
$t = new Ticket($v);
if($t && @$t->delete()) $i++;
}
$msg="$i of $count selected tickets deleted";
} // NOW MY CODE
elseif(isset($_POST['banDelete'])){
$i=0;
foreach($_POST['tids'] as $k=>$v)
{
$t = new Ticket($v);
if($t && @$t->delete())
{
if($beenBanned=$t->getEmail()){
if(Banlist::add($t->getEmail(),$thisuser->getName())){}
$msg .= "$beenBanned banned!<br />";}
$i++;
}
}
$msg .= "$i of $count selected tickets deleted <br />$i of $count emails banned.";
}}
break;

All of your effected tickets will now be deleted and the emails banned. You will also be alerted to the result so you can double check your email addresses and unban if necessary.

Posted in osTicket - Tagged ban, delete, mass, mod, modification, osTicket, ticket

Emacs> Use % to jump to the matching parenthesis/brackets

Oct26
2010
Written by Scott Rowley

Found the following while working on other emacs configurations, works great for when your code gets out of hand:

;;; Use "%" to jump to the matching parenthesis.
(defun goto-match-paren (arg)
"Go to the matching parenthesis if on parenthesis, otherwise insert
the character typed."
(interactive "p")
(cond ((looking-at "\s(") (forward-list 1) (backward-char 1))
((looking-at "\s)") (forward-char 1) (backward-list 1))
(t (self-insert-command (or arg 1))) ))
(global-set-key "%" `goto-match-paren)
Posted in Emacs - Tagged bracket, edit, Emacs, jump, parenthesis, search

BASH> How to install perl modules through CPAN on Ubuntu

Oct26
2010
Written by Scott Rowley

Install all dependent packages for CPAN

sudo apt-get install build-essential

Invoke the cpan command as a normal user

cpan

Once you hit on enter for “cpan” to execute, you be asked of some few questions. To make it simple for yourself, answer “no” for the first question so that the latter ones will be done for you automatically.

Enter the commands below

make install
install Bundle::CPAN

Now all is set and you can install any perl module you want. examples of what installed below:

cpan prompt> install IO::File
cpan prompt> install Net::SMTP_auth
cpan prompt> install Email::MIME::Attachment::Stripper
cpan prompt> install Mail::POP3Client
Posted in BASH - Tagged BASH, cpan, install, module, Perl

Emacs> Remove welcome screen/splash from emacs

Oct26
2010
Written by Scott Rowley

If you are tired of seeing the welcome screen, despite it being the 486th time you’ve opened emacs just perform the following:

Edit your .emacs file and add the following:

;; Remove splash screen
(setq inhibit-splash-screen t)
Posted in Emacs - Tagged BASH, Emacs, splash, welcome

BASH> Remove tabs from output

Oct26
2010
Written by Scott Rowley

In order to remove tabs from your output (say to get a specific variable) use the ‘tr’ command, for example

In my zone.file the line containing “Serial” looks like the following:
If I performed

grep Serial zone.file

I would get the following output

 2009110904 ; Serial (yyyymmdd##)

You can’t see them here but there are several tabs before that date. In my example I want to get just the actual serial number (2009110904). To do this I’ll first strip off the “; Serial…” information;

grep Serial zone.file | awk -F; {'print $1'}

This command is telling it to look for the ; special character and break up the output there, then from there it is told to print the first column of information this results in:

 2009110904

The problem here is that if we want this to be our variable we are actually working with ” 2009110904″ instead of the desired “2009110904” In this particular case we know those are tabs not spaces. So we’ll need to use tr in order to remove those tabs:

grep Serial zone.file | awk -F\; {'print $1'} | tr -d 't'

This will return to us exactly what we want

2009110904
Posted in BASH - Tagged awk, BASH, grep, tab, tr

BASH> Hello World Script

Oct26
2010
Written by Scott Rowley

So you’ve either recently come to the Unix world or you are finally getting around to some shell scripting to ease your daily operations (Say hi Jim!). So for starters what *IS* bash scripting? Scripting in general is making a program or “script” do all or most of your work for you. For instance if you wanted to find every instance of the word “hosting” in a particular file that is 30,000 lines long. That would take a LONG time doing that by hand and you would likely miss several along the way (being a fallible human and all). So instead we would use a grep (or similiar command) from the command line.
Well that may be easy enough for just one command but what if we then need to check all of those lines that are found and seperate them by date or some other criteria, then sort them out etc? For this we will use scripting. We can also use scripting for events that we want to take place every single day, whether it be simple or complex. This can be done via a cronjob, but we can get to that in a later article. So first off we’ll need to find where our “bash” resides…

which bash > helloWorld.sh

“which bash” will give us the location of the bash that is being used within our path. The > will send that result into a new file titled “helloWorld.sh” that we will use for our script. Now if we open up that file we will have something like the following:

/usr/bin/bash

Nothing else should be in our file at this point. This is good but not quite what we need. We need to add #! in front of this. This tells our script that we will be using /usr/bin/bash as our shell to run the rest of this script.

#!/usr/bin/bash

To complete our very first script all we’ll need to do is enter in the following a few lines (doesn’t matter how many) after our #!/usr/bin/bash line, like so:

#!/usr/bin/bash
echo "Hello World!"

Now we have our script ready, we just need to execute it. There are two ways to accomplish this, first we can simply chmod the file to give it the execute (x) permission. For simplicity sake we’ll say its:

chmod 755 helloWorld.sh

The 7 sets it so that the owner (you) can do anything with the file, the first 5 sets it so that anyone in its group can read and execute it and likewise for the last 5 but for this is for everyone, not just the group. More on chmod and chown in future articles.

Now that we have our file chmod’d to be executable we can run it right from where we are by typing

./helloWorld.sh

and our output should be simply:

Hello World!

As mentioned there are two ways to execute the file. For the second method we could type the following and not have to worry about permissions (only ownership — but since we own it we really don’t have to worry about that either).

/usr/bin/bash ./helloWorld.sh

And, again, our output would be the same:

Hello World!

Congratulations, you’ve just made your first Bourne Again Shell (Bash) Script.

Posted in BASH - Tagged BASH, chmod, command, echo, hello world, script

BASH> Get all but the last field

Oct26
2010
Written by Scott Rowley

Recently I had need of cutting up domain names such as domain.com, this is easy enough for as simple a domain as this. However, the problem arises when you need to cut up something more like “education.k12.ia.us”. In order to get the extension alone in either case you can do the following:

echo domain.com | awk -F. {'print $2'}
com

Now normally if you have a domain as simple as example.com with only one period then you can can just do the opposite of this and print $1:

echo domain.com | awk -F. {'print $1'}
domain

The problem with more complex URLs is that awk’s field delimiter is now looking at multiple periods to look at, could be just one or it could be two, three, four or more.

To get the final extension in this case then we’ll use the following:

echo education.k12.ia.us | awk -F. {'print $NF'}
us

Then for the rest of it we’ll have to reverse it, then cut off the first field then reverse it again:

echo education.k12.ia.us | rev | cut -d. -f2- | rev
education.k12.ia
Posted in BASH - Tagged awk, BASH, delimiter, domain, extension, field

BASH> if ARRAY [does not] contains string

Oct26
2010
Written by Scott Rowley

Check if an array contains a given string:

teams=(chiefs broncos chargers raiders)
if [[ ${teams[*]} =~ broncos ]]
then
echo "VICTORY!"
fi

Or, if you don’t want it to contain the string then:

teams=(cardinals 49ers seahawks rams)
if [[ ${teams[*]} =~ broncos ]]
then
echo "This conference sucks"
else
echo "VICTORY!"
fi
Posted in BASH - Tagged array, BASH, contain, string

Perl> Get IP only from logfiles

Oct26
2010
Written by Scott Rowley

Being an ISP admin, I have regular need to find IP addresses listed in large logfiles. The following will grab anything that appears to be an IP and list it out for you, from there you can sort or whatever you want to do with the list.

perl -ne 'print "$&n" while m#d+.d+.d+.d+#g' <logfile>

Or just throw it in a bash script for easier remembering:

getip.sh

#!/bin/bash
perl -ne 'print "$&\n" while m#\d+\.\d+\.\d+\.\d+#g' $1;
Posted in Perl - Tagged BASH, IP, log, logfile, Perl, print
« Older Entries Newer Entries »

Corrections? Questions? Comments?

Find an error?
Everything work out great for you?
Have some feedback?
Like to see something added to the article?

PLEASE leave us a comment after the article and let us know how we are doing, or if something needs corrected, improved or clarified.

Thank you!
- The Management

Advertisement

Sudo Bash
By Geeks - For Geeks

Back to Top