I've got a file with lots of commands I want to run in it. They're formatted like so:
cp /path/to/file /path/to/new/file
and on and on and on.
Hundreds of them.
Anyways, I'd like to execute them one at a time, then check what time it is, and repeat this process until 7am.
I can isolate single lines without much trouble using this command:
head +$num <file> | tail -$num
(num being the number of files that have been copied so far, initialized to 1)
...but that only outputs the command I want to execute, it doesn't actually run it, obviously.
So how do I go about executing that command? Or is there an easier way to go about it?
awk
July 23, 2007, 12:18pm
2
profiction:
I've got a file with lots of commands I want to run in it. They're formatted like so:
cp /path/to/file /path/to/new/file
and on and on and on.
Hundreds of them.
Anyways, I'd like to execute them one at a time, then check what time it is, and repeat this process until 7am.
I can isolate single lines without much trouble using this command:
head +$num <file> | tail -$num
(num being the number of files that have been copied so far, initialized to 1)
...but that only outputs the command I want to execute, it doesn't actually run it, obviously.
So how do I go about executing that command? Or is there an easier way to go about it?
Since you can isolate the command, try this-
for <your loop>
do
CMD=$(head +$num <file> | tail -$num)
date; $CMD
done
Hey, thanks a lot for your response.
I figured out another way of doing it in less lines after reading your suggestion, check it out for your future reference as well.
while [ $hour -ne "07" ]
do
`head -$num file | tail +$num`
num=`expr $num + 1`
hour="`date '+%H'`"
done
Thanks again!
If you want to execute each statement and check everytime if it is the
seventh hour, the following will create a 'Temp' shell script with all your
commands and a function 'f_test_time':
echo '#!/bin/ksh' > Temp
echo 'function f_test_time {}' >> Temp
echo 'typeset -i mDate' >> Temp
echo 'mDate=`date +"%H"`' >> Temp
echo 'if [ ${mDate} -eq 7 ]; then' >> Temp
echo 'echo "It is the seventh hour -- exiting."' >> Temp
echo 'exit' >> Temp
echo 'fi' >> Temp
echo '}' >> Temp
while read mLine
do
echo $mLine >> Temp
echo 'f_test_time' >> Temp
done < input_file