run script simultaneous


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting run script simultaneous
# 1  
Old 12-07-2010
Tools run script simultaneous

I have 5 scripts, basicly do the same thing. Use expect and telnet to devices.

First set the variables and the script as follow
Code:
spawn telnet $ipaddr
expect "Username:"
send -- "$usuario\r"
expect "Password:"
send -- "$password\r"
send -- "\r"
send -- "\r"
send -- "copy running-config tftp:\r"
expect "[]?"
send -- "$tftpserver\r"
expect "]?"
send -- "$nameconfig.$gpo.[exec ps -ef | grep -w [pid] | head -1 |  awk {{print $3}}]\r"
expect "#"
send -- "exit\r"
expect eof

When I run the scripts 1 or 2, both run without problems.

Searching to reduce the time, I need run the 5 scripts simultaneously but when configure the /etc/crontab sometimes run 3, sometimes run 4, sometimes run 5.

Do you have a clue?
# 2  
Old 12-07-2010
Could you run it background like : (setting the expected IP values)
(of course the following code may need to be fixed but here is the idea)

Code:
Xpec(){
spawn telnet $1
expect "Username:"
send -- "$usuario\r"
expect "Password:"
send -- "$password\r"
send -- "\r"
send -- "\r"
send -- "copy running-config tftp:\r"
expect "[]?"
send -- "$tftpserver\r"
expect "]?"
send -- "$nameconfig.$gpo.[exec ps -ef | grep -w [pid] | head -1 |  awk {{print $3}}]\r"
expect "#"
send -- "exit\r"
expect eof
}

for i in IP1 IP2 IP3 IP4 IP5
do
Xpec "$i" &
done

# 3  
Old 12-07-2010
thanks for the help.

I need to know why is the root cause of this behavior, any idea?
# 4  
Old 12-08-2010
What OS are you running?
Show us what lines you have in your crontab
Do your "expect" script requires to be run with a specific user or in a special environment ? (where $usuario as well as $password do come from ?)
# 5  
Old 12-08-2010
The OS is linux FC13

The lines in the crontab is:

Code:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/home/yuri
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  *  command to be executed
00 22 * * 1-7 yuri /home/yuri/script1
00 22 * * 1-7 yuri /home/yuri/script2
00 22 * * 1-7 yuri /home/yuri/script3
00 22 * * 1-7 yuri /home/yuri/script4
00 22 * * 1-7 yuri /home/yuri/script5

The user for run the script is yuri and not need nothing special in the environment.
# 6  
Old 12-08-2010
Why don't you gather it into one script ?

Code:
 00 22 * * 1-7 launcher


Code:
$ cat launcher
yuri /home/yuri/script1&
yuri /home/yuri/script2&
yuri /home/yuri/script3&
yuri /home/yuri/script4&
yuri /home/yuri/script5&

# 7  
Old 12-08-2010
in background all run very well...thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simultaneous calling of url

Hello I want to call multiple sites simultaneously by xargs or parallel for example a.com/srv/1 a.com/srv/3 a.com/srv/2 a.com/srv/n That means 500 different sites will be called in a moment Then I use command I call a url at the same time. I need to call each url once, but every 500... (1 Reply)
Discussion started by: mnnn
1 Replies

2. Homework & Coursework Questions

Limit simultaneous file access

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: So my problem is: 4990 of 5000 users should be able to access a file. How can this be accomplished. 2.... (1 Reply)
Discussion started by: protiss
1 Replies

3. UNIX for Dummies Questions & Answers

Help with ls to input for simultaneous editing

I just registered today and started unix about a month ago. I'm trying to make a script where I can add commands or text to the end of files in a listing. $ echo "#text_or_command" >> #List of files from ls I can't seem to find/understand it on these fourms. Could it be done at... (4 Replies)
Discussion started by: 62583
4 Replies

4. Shell Programming and Scripting

Cron job to prevent simultaneous script

I'm using a shared server on Hostgator (Linux CentOS). I'm trying to set a cron job using the Control Panel that will check if its already running before starting a new one. I've tried the following... * * * * * && but I get this error emailed to me... /bin/sh: line 0: Any... (5 Replies)
Discussion started by: tech9821
5 Replies

5. UNIX for Dummies Questions & Answers

Simultaneous file read operation

Hi All, I need information on file handling in UNIX enviornment. If in UNIX enviornment I have two process.. P1 P2 Both accessing the same file simultaneosuly(read operation).. Suppose P1 opened the file in read mode first and started reading the file.. Then P2 opens the same file in... (5 Replies)
Discussion started by: chibob
5 Replies

6. UNIX for Dummies Questions & Answers

Problems with simultaneous access to a server

Hello, I'm working in a project where several procedures are programmed using UNIX scripts. One of these scripts is launched in several threads. When performing these threads an scp command to another server it gives out. This error happens only sometimes, others not and each time for a... (5 Replies)
Discussion started by: Hector_Saura
5 Replies

7. UNIX for Dummies Questions & Answers

simultaneous network start

Hi! I need to start a program at several hosts in the network at the same time. Starting time difference should be no more than several milliseconds. What is the best way to do that? Thanks! (5 Replies)
Discussion started by: harjar
5 Replies

8. Shell Programming and Scripting

running simultaneous awks

Hello, I have an awk command that searches and replaces. I have multiple searches, but I do not want to do them one after the other. Is there a way in awk to run search/replace at the same time. thanks, (3 Replies)
Discussion started by: ctcuser
3 Replies

9. UNIX for Dummies Questions & Answers

Simultaneous printing

I am running AIX 4.3 and network printing setup with HP Jetdirect. I would like to be able to send the same printout to both of the network printers at the same time. They are both PCL data stream. I have tried to make this work by linking the two print que, by the results are unpredictable. Is... (1 Reply)
Discussion started by: sjk303
1 Replies
Login or Register to Ask a Question