0

I have a csh script (I have to use csh, I can't use bash) called new_script which calls another script called soak_script 12 times. The soak_script sleeps for 12 hrs and then does some tests.

My problem is that my original script (new_script) terminates automatically after soak_script executes once. If I reduce the sleep time from 12 hrs to 30 sec, the entire script works fine and soak_script is executed 12 times as it should. Why is this happening? Please help me. I am a beginner at linux and scripting and I am really lost.

#!/bin/csh -f
clear

echo "*****************************SIMULATION STARTED***********************************"
echo ""
echo "Sim Start Time : `date`"
echo "Sim Folder     : ${cwd}"
echo ""
ls | grep -E 'soak|scan' > ls_all
echo "List of all simulation sub-folders:"
cat ls_all
echo ""

foreach line ( "`cat ls_all`" )
    if ($line =~ *scan*) then
        cd .. 
        echo "CURRENT DIRECTORY: ${PWD}"
        echo "Copying char_nosleep.c to char.c"
        cp char_nosleep.c char.c
        if ($? != 0) then 
            echo "Copying failed"; exit 2
        endif
        cd /u/rahul7/p4/prod/virgo2/diags/src
        echo "CURRENT DIRECTORY: ${PWD}"
        echo "Making char_nosleep.c for $line"
        make
        if ($? != 0) then 
            echo "Making failed"; exit 3
        endif
        wait
        echo "****************************************************************************************************************************************************************************"
        cd bin/vdma/TestSet2_100_100
        cd $line
        echo "CURRENT DIRECTORY: ${PWD}"
        echo "RUNING.."
        echo "Run Start Time : `date`"
        ls | grep ^data > ls_run
        foreach command ( "`cat ls_run`" )
            if ($command =~ *Micron*) then
                ./$command > mcrn_run_out &
            else if ($command =~ *Samsung*) then
                ./$command > ssung_run_out &
            else if ($command =~ *Toshiba*) then
                ./$command > tshba_run_out &
            else
                echo "Micron, Toshiba or Samsung run file not found in $(pwd)!"; exit 4;
            endif
        end
        wait
        rm -f ls_run
        echo "Run End Time : `date`"
        echo "****************************************************************************************************************************************************************************"
        cd ..

else if ($line =~ *soak*) then
    cd .. 
    echo "CURRENT DIRECTORY: ${PWD}"
    echo "Copying char_sleep_12hr.c to char.c"
    cp char_sleep_12hr.c char.c
    if ($? != 0) then 
        echo "Copying failed"; exit 2 
    endif
    cd /u/rahul7/p4/prod/virgo2/diags/src
    echo "CURRENT DIRECTORY: ${PWD}"
    echo "Making char_sleep_12hr.c for $line"
    make
    if ($? != 0) then 
        echo "Making failed"; exit 3
    endif
    wait
    echo "****************************************************************************************************************************************************************************"
    cd bin/vdma/TestSet2_100_100
    cd $line
    echo "CURRENT DIRECTORY: ${PWD}"
    echo "RUNING.."
    echo "Run Start Time : `date`"
    ls | grep ^data > ls_run
    foreach command ( "`cat ls_run`" )
        if ($command =~ *Micron*) then
            ./$command > mcrn_run_out &
        else if ($command =~ *Samsung*) then
            ./$command > ssung_run_out &
        else if ($command =~ *Toshiba*) then
            ./$command > tshba_run_out &
        else
            echo "Micron, Toshiba or Samsung run file not found in $(pwd)!"; exit 4;
        endif
    end
    wait
    rm -f ls_run
    echo "Run End Time : `date`"

    echo "****************************************************************************************************************************************************************************"
    cd ..
endif
end

rm -f ls_all
echo "Sim End Time : `date`"
Rahul
  • 371
  • 1
  • 2
  • 12
  • 1
    If you need to execute your script every 12 hours or so, consider using a cron job instead of putting it up in another wrapper script. – devnull Jul 10 '13 at 14:24
  • Impossible to help without seeing the scripts. – Keith Thompson Jul 10 '13 at 14:28
  • does the **soak_script** end with a `quit`? give us some more information regarding the scripts so we can help... – user2141046 Jul 10 '13 at 14:29
  • I've added my entire script. The ls_all contains the names of folders which have the run scripts (there are 3 scripts in each folder, which have to be run simultaneously). There are 12 such folders, half have soak_script and half have scan_script. The scan_script is the same as soak_script but it does not sleep. The scan and soak are run alternatively. – Rahul Jul 10 '13 at 14:36
  • `exit 2; echo "Copying failed"` -- The `echo` will never execute. (This is probably irrelevant to your question.) – Keith Thompson Jul 10 '13 at 20:20
  • @KeithThompson It might not be irrelevant. At the very least, if it is ending at one of those points the error messages are not being shown which makes debugging harder. – SethMMorton Jul 11 '13 at 03:51
  • goodness `make`? what is it, a *mentor graphics* script? in any case, which line is responsible for the sleep? since you say that it works well when asked to sleep 30 sec, but fail to sleep 12 hrs i'd bet you have a problem with the time format. – user2141046 Jul 11 '13 at 06:15
  • @KeithThompson Yeah you're right. I changed that. – Rahul Jul 12 '13 at 01:04
  • @SethMMorton I'm sure that it doesnt exit at any of those places because the log shows that the make is a success, the first set for soak runs fine but after that it exits immediately, without even printing the **echo "Run End Time : `date`"** line. – Rahul Jul 12 '13 at 01:10
  • @user2141046 Thanks for the tip. The sleep takes place in the char_sleep_12hr.c file. It's written by someone else so I'll contact them and get a better understanding of it's working. BTW this code tests flash drives. – Rahul Jul 12 '13 at 01:11
  • @Rahul: And the problem still occurs after you made that change, right? – Keith Thompson Jul 12 '13 at 01:15
  • Does csh have an exit-on-error feature like bash? Is it on? – Kevin Jul 12 '13 at 02:17
  • No plain `sh` either? I understand if you can't use Bash, but do you rilly rilly have to use csh? – tripleee Jul 12 '13 at 03:16
  • @tripleee yeah you're right. I hadn't tried that. I'm gonna use sh and try it now – Rahul Jul 16 '13 at 16:33
  • @Keith yeah it does.. – Rahul Jul 16 '13 at 16:33
  • Works in sh. Thanks everyone for your help. – Rahul Jul 25 '13 at 20:50

0 Answers0