Linux device driver intro 1
Linux device driver intro 2
Linux device driver intro 3
Thursday, December 30, 2010
linux device driver intros from veda hyd
Friday, November 26, 2010
Directory watcher
Directory watcher will update update.txt file with what are the file or directories removed or added from previous run of script.
This is totally shell script.
First copy with dir_watcher name and give execution permissions and run as "./dir_watcher dir_path"
For the first time runs. It takes snapshot of ur directory structure which was provided in cmd.
When second time runs it will take snapshot of directory and if any new files or dir are added then those updates will be written in to update.txt in parent directory.
If dir path not mentioned it will take present dir.
Note:- It won't give information of updated files.
Put this script in crontab so it will run periodically and updates log file with changes.
ex:- 0 12 * * * sh /bin/dir_watcher /home/balu/project/
So, every day at 12 noon it will run and updates the update.txt file in "/home/balu/project/"
This is totally shell script.
First copy with dir_watcher name and give execution permissions and run as "./dir_watcher dir_path"
For the first time runs. It takes snapshot of ur directory structure which was provided in cmd.
When second time runs it will take snapshot of directory and if any new files or dir are added then those updates will be written in to update.txt in parent directory.
If dir path not mentioned it will take present dir.
Note:- It won't give information of updated files.
Put this script in crontab so it will run periodically and updates log file with changes.
ex:- 0 12 * * * sh /bin/dir_watcher /home/balu/project/
So, every day at 12 noon it will run and updates the update.txt file in "/home/balu/project/"
Wednesday, November 3, 2010
Use cmd line arguments for expect script.
Below I have given a small example to get a file from ftp server. This code was written using expect.
Usage:- HOST PROMPT$ expect ftp_get_file.exp < IP > < user_name > < password > < file_to_get >
EX:-
#!/usr/bin/expect -f < IP >
set ip [lrange $argv 0 0]
set username [lrange $argv 1 1]
set password [lrange $argv 2 2]
set file [lrange $argv 3 3]
set timeout -1
#Spwan the Cfm1 Util stub
spawn ftp $ip
expect ":"
send -- "$username\r"
sleep 1
expect "Password:"
send -- "$password\r"
sleep 2
expect ">"
send -- "bi\r"
sleep 1
expect ">"
send -- "ha\r"
sleep 1
expect ">"
send -- "mget $file\r"
sleep 2
expect "?"
send -- "y\r"
sleep 1
expect ">"
send -- "by\r"
sleep 1
expect eof
NOTE:- If ur password contain any special character then use "\" in front of those characters.
Usage:- HOST PROMPT$ expect ftp_get_file.exp < IP > < user_name > < password > < file_to_get >
EX:-
#!/usr/bin/expect -f < IP >
set ip [lrange $argv 0 0]
set username [lrange $argv 1 1]
set password [lrange $argv 2 2]
set file [lrange $argv 3 3]
set timeout -1
#Spwan the Cfm1 Util stub
spawn ftp $ip
expect ":"
send -- "$username\r"
sleep 1
expect "Password:"
send -- "$password\r"
sleep 2
expect ">"
send -- "bi\r"
sleep 1
expect ">"
send -- "ha\r"
sleep 1
expect ">"
send -- "mget $file\r"
sleep 2
expect "?"
send -- "y\r"
sleep 1
expect ">"
send -- "by\r"
sleep 1
expect eof
NOTE:- If ur password contain any special character then use "\" in front of those characters.
Friday, October 8, 2010
Expect scritp runs multiple cmds taking as a variable
Hi as part of unit testing i have written a expect script that expects same things but i need to send some list of cmds. For the first time i have written in the sequence of expect, send, sleep and then for the second and go on. But script is very lengthy if i want to see execution flow of cmds i need to scroll down to entire script.
So i find an alternate solution where i kept all my cmds in one varible and split on newline (i used newline, can be changed) and send these cmds one by one using for.
Below script is small example which will explain what i have done. Pretty simple logic and very basic too.
Have a look......
#!/usr/bin/expect -f
set data "ls
pwd
cd ..
ls
pwd
cd ..
pwd
ls
cd /etc
pwd
ls
cd /home/baluenigma
exit"
#Spwan the Cfm1 Util stub
spawn /bin/bash
match_max 100000
foreach line [split $data \n] {
expect "[baluenigma@192.168.2.79 *]#"
send -- "$line\r"
sleep 1
}
Above data is varible which holds all cmds which need to be executed.
Foreach is used to read data varible and split on newline char and line varible takes that value. Now expect cmd expects "[baluenigma@192.168.2.79 *]#" here '*' used because pwd will change when i used cd cmds which are in data variable.
So i find an alternate solution where i kept all my cmds in one varible and split on newline (i used newline, can be changed) and send these cmds one by one using for.
Below script is small example which will explain what i have done. Pretty simple logic and very basic too.
Have a look......
#!/usr/bin/expect -f
set data "ls
pwd
cd ..
ls
pwd
cd ..
pwd
ls
cd /etc
pwd
ls
cd /home/baluenigma
exit"
#Spwan the Cfm1 Util stub
spawn /bin/bash
match_max 100000
foreach line [split $data \n] {
expect "[baluenigma@192.168.2.79 *]#"
send -- "$line\r"
sleep 1
}
Above data is varible which holds all cmds which need to be executed.
Foreach is used to read data varible and split on newline char and line varible takes that value. Now expect cmd expects "[baluenigma@192.168.2.79 *]#" here '*' used because pwd will change when i used cd cmds which are in data variable.
Subscribe to:
Posts (Atom)