#!/bin/bash
i="0"
echo ""
echo "##################"
echo "LAUNCHING REQUESTS"
echo " COUNT: $2 "
echo " DELAY: $3 "
echo " SESSID: $1"
echo "##################"
echo ""
while [ $2 -gt "$i" ]
do
i=$[$i+1]
php avtest.php $1 $4 &
echo "EXECUTING REQUEST $i"
sleep $3
done
here is a better/modified script in bash
#!/bin/bash
i="0"
#startTime=`date +%s`
startTime=$(date -u +%s)
startTime=$[$startTime+$1+5]
#startTime=$($startTime+$1+5)
dTime=`date -d @$startTime`
echo ""
echo "##################"
echo "LAUNCHING REQUESTS"
echo " COUNT: $1 "
echo " DELAY: 1 "
#echo " EXECUTION: $startTime "
echo " The scripts will fire at : $dTime "
echo "##################"
echo ""
while [ $1 -gt "$i" ]
do
i=$[$i+1]
php avtestTimed.php $1 $3 $startTime &
echo "QUEUEING REQUEST $i"
sleep 1
done
Here’s a direct translation
But it would make more sense to read the command line parameters into variables named after what they’re for and not rely on remembering argument ordering.
A brief errata in the conversion:
I use a here string to represent multiline text. I could also have put in multiple
printstatements to more closely mimic the bash versionIn bash arguments are accessed as numbered variables, starting with $1 and going up. In Perl the argument list is represented by the array @ARGV, which is numbered starting at zero (like arrays in most languages). In both bash and Perl the name of the script can be found in the variable $0.
In Perl arrays are written as
@arraynamewhen refering to the entire array, but they use $arrayname[index] when accessing array members. So the Perl$list[0]is like the bash${list[0]}and the Perl@listis like the bash${list[@]}.In Perl variables are declared with the
mykeyword; the equivalent in bash would bedeclare.I’ve used the
systemfunction for spawning background processes. Its argument can be simply the command line as you might use it in bash.Unlike
echo,printrequires to be told if there should be a newline at the end of the line. For recent versions of Perl thesayfunction exists which will append a newline for you.The Perl
sleepfunction is pretty self-explanatory.EDIT: Due to a typo
$iin the print statement had been represented as$nileading to runtime errors. This has been corrected.