Showing posts with label BASH. Show all posts
Showing posts with label BASH. Show all posts

Monday, November 12, 2012

Delete lines inside a file matching a pattern

You can use pattern matching of sed to do so !

sed -i '/pattern/d' filename
Example: To remove the lines containing "server" from foo.txt ,do this
sed -i '/server/d' foo.txt

I felt this usefull often . For more SED tutorials , visit http://www.grymoire.com/Unix/Sed.html

Sunday, November 11, 2012

MRTG Start Up Script for Ubuntu

MRTG as a Start Up Service in Ubuntu

I am monitoring a lot of routers and switches of my organization using MRTG ( Multi Router Traffic Grapher ) . It is one of the best tools to give you an overview of bandwidth utilizations, CPU/Memory Utilizations etc. Here is a small bash script to make all these MRTG process act as a service which is automatically start up at reboot.

Details of MRTG

I am using MRTG with RRDTool using routers.cgi script. My MRTG configurations arrangements are like
  • Location1 Folder
    • router.cfg
    • switch.cfg
    • servers.cfg
  • Location2 Folder
    • router.cfg
    • switch.cfg
    • servers.cfg
  • Location3 Folder
    • SubLocation1 Folder
      • router.cfg
      • switch.cfg
      • servers.cfg
    • SubLocation2 Folder
      • router.cfg
      • switch.cfg
      • servers.cfg
    • router.cfg

Friday, November 02, 2012

Keyboard shortcut to Open terminal in Ubuntu

CTRL + ALT + T
is the default key combination to open command line terminal ( BASH terminal ) in Ubuntu. This can be further changed by going to System -> Preferences -> Keyboard Shortcuts

Thursday, October 25, 2012

Installing / Uninstalling .deb files in Ubuntu

In Ubuntu , the package files are in .deb files . To install the packages file , you should be having administrative password.


Installing .deb debian package file in Ubuntu


  • Double click the .deb file , it will be automatically opened with the GDebi Package manager and you can install it
  • From command line , use this command to install a package .
    sudo dpkg -i PACKAGEFILE.deb

Uninstalling a package in Ubuntu

  • From command line, use this command
    sudo dpkg -r PACKAGENAME

Sunday, April 04, 2010

tweeting from the BASH terminal

i feel this an awesome script..tweet from command line terminal in linux..
script is as follows:

#!/bin/bash

username="yourUserName" ;
password="yourPassword";

URL="http://twitter.com/statuses/update.xml" ;

if [ $(echo "$1" | wc -c ) -gt 140 ]
then
echo "Whoo: Its more than 140 characters"
exit 0;
fi

result=$(curl -u $username:$password -d status="$1" $URL) ;

exit 0 ;

save this in some file name "tweet" and make it executable ( chmod +x tweet )
And for simplicty add an alias ..
Now tweet from terminal using the command
tweet "tweeting from the command line"

Monday, March 22, 2010

Add file to VLC playlist by right clicking

I found a simple nautilus script which is very usefull for those who usually plays something in VLC. Script to add a file to VLC playlist by simple right clicking on the file .

What to do ?


cd ~/.gnome2/nautilus-scripts

touch "Add to VLC Playlist"

then copy the following to the file "Add to Playlist"

Pre-requisite: Install zenity from your package manager


#!/bin/bash

## Ny Narendra Sisodiya, for SchoolOS
## narendra.sisodiya@gmail.com
## modified by: IRFAN NASEEF P
##             irfan@nitc.ac.in

checkFileType()
{
  file $1 | grep -i "audio" || file $1 | grep -i "video" || file $1 | grep -i "ogv" || file $1 | grep -i "mpeg"
  RES=$?
  if [ $RES -eq 0 ]
  then
      return 0
  else
      zenity --error --title "VLC says: " --text "Error: $FILENAME is not an audio/video file"
      return 1
 
   
   fi
}

IFS=$'\n'
for FILENAME in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
  checkFileType $FILENAME

  if [ $? -eq 0 ]
  then
    vlc --started-from-file --one-instance-when-started-from-file --playlist-enqueue "$FILENAME"
    
 fi
done

exit 0

################

Then save ..

Now you can see a 'Scripts' option when you right click , and a 'Add to VLC Playlist' in it. Now you can directly add files to playlist by simply right clicking .