Feeds:
Posts
Comments

Archive for the ‘Shell Scripts’ Category

With the WA3002G4 wireless router i got recently from my friend i made a wifi hotspot in home. Haven’t been downloading a lot since my script to reboot old teracom router was not working with the new one.Thinking that I should do something on the day which will come only in every four years I modified the old script to work with the new wireless router and I am sharing it here.

#!/usr/bin/env expect

set username admin
set pass admin
set host 192.168.1.1

spawn telnet ${host}

expect -re "Login:"
send "${username}\r"

expect -re "Password:"
send "${pass}\r"

expect -re "Main Menu"
send "13\r"
send "1\r"
expect eof 
Advertisements

Read Full Post »

A slightly edited version of the script to restart router written by Madhusudan.C.S to make it work with teracom router given by bsnl.

#!/usr/bin/env expect

set username admin
set pass admin
set host 192.168.1.1

spawn telnet ${host}

expect -re "Login:"
send "${username}\r"

expect "Password:"
send "${pass}\r"

expect -re "successful"
send "console enable\r"
send "restart\r"
expect eof 

Read Full Post »

Iam back with another shell script written for my sis as part of her assignment. This time what i wanted to do is to count the unique words in a file and to print it in alphabetical order. For that i iterated through the words in the given file using for loop, filtered out the unique words using sort -u and counted it using wc -l.

#!/usr/bin/bash
echo Enter the filename
read fn

for WORD in $(cat $fn)
do
	echo "$WORD"
done | sort -u | wc -l	

 for WORD in $(cat $fn)
 do
  echo "$WORD "
 done | sort -u

Hope this will help someone to do his/her assignment 😀

Read Full Post »

Ok here is a script to cipher text contents in a file. It will shift the letters to the fifth letter to its right, ie if a is the letter, it will change it to f.

echo Enter the filename
read fn

while read -n 1 letter
do
  case $letter in
    '')
      echo
    ;;
    ' ')
      printf ' '
    ;;
	'.')
	  printf '.'
	;;
    *)
      asci=$(printf %d \'$letter)
      ((asci+=5))
      fwd_letter=$(printf "\\$(printf "%03o" $asci)")
      printf "$fwd_letter"
    ;;
  esac
done < $fn

You can decipher it by just replacing the + in 18th line to
Note : This is a assignment my sis got from IGNOU. I hope this will help someone to do his/her assignment 🙂

Read Full Post »

Few days ago i wrote a script to update the status message in pidgin with the title of the song playing in audacious music player.It is written in python.it makes use of the dbus for the inter application communication.when you invoke that script it just appends the title of the song currently playing in audacious as the status message in pidgin .i used the shell command $watch to invoke it in every 30 seconds so that the status message gets updated with the songtitle within 30 seconds after the song change.You can reduce the number of seconds so that the status message gets updated frequently reducing the time delay between the song change and updation of status message.What the script does is, it retrieves the song title from the audacious music player using dbus.Then this songtitle is assigned as the status message in pidgin by communicating through dbus.This script needs dbus and py-dbus.So make sure that you have both packages installed in your system.

Here is the script :

def set_message(message):
# Get current status type (Available/Away/etc.)
current = purple.PurpleSavedstatusGetType(purple.PurpleSavedstatusGetCurrent())
# Create new transient status and activate it
status = purple.PurpleSavedstatusNew(“”, current)
msg=”Now Playing: ”
emsg=msg+message
purple.PurpleSavedstatusSetMessage(status, emsg)
purple.PurpleSavedstatusActivate(status)

import dbus
session_bus=dbus.SessionBus()
proxy = session_bus.get_object(“im.pidgin.purple.PurpleService”, “/im/pidgin/purple/PurpleObject”)
purple = dbus.Interface(proxy, “im.pidgin.purple.PurpleInterface”)
proxy1 = session_bus.get_object(‘org.mpris.audacious’,’/TrackList’)
purple1 = dbus.Interface(proxy1,’org.freedesktop.MediaPlayer’)
ct = purple1.GetCurrentTrack()
proxy2 = session_bus.get_object(‘org.mpris.audacious’,’/org/atheme/audacious’)
purple2 = dbus.Interface(proxy2,’org.atheme.audacious’)
currentsong = purple2.SongTitle(ct)
print currentsong
set_message(currentsong)

Running this script will update the status message just once , so u have to shell command $watch as i said earlier.if you dont want to do this things manually, dont worry! i got package for this, grab it from here http://ragsagar.freehostia.com/pidgin-audacious_plugin.tar.gz , untar it and run the installer..

$wget http://ragsagar.freehostia.com/pidgin-audacious_plugin.tar.gz

$tar -xvf pidgin-audacious_plugin.tar.gz

$cd pidgin-audacious\ plugin/

$sudo chmod a+x installer

$./installer

Now run the script using this command :

$pidgin-plugin

PS: Make sure that you have both audacious and pidgin already running

Read Full Post »

%d bloggers like this: