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

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?

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)

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

thanks for the help.

I need to know why is the root cause of this behavior, any idea?

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 ?)

The OS is linux FC13

The lines in the crontab is:

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.

Why don't you gather it into one script ?

 00 22 * * 1-7 launcher
$ cat launcher
yuri /home/yuri/script1&
yuri /home/yuri/script2&
yuri /home/yuri/script3&
yuri /home/yuri/script4&
yuri /home/yuri/script5&

in background all run very well...thanks