Run script every minute and terminate after specified number of executions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run script every minute and terminate after specified number of executions
# 1  
Old 02-03-2014
Run script

when it runs and look at my acron.log file it generates an error as below
Code:
/tmp/prog.sh: line 4: [1: command not found
/tmp/prog.sh: line 7: 1=1: command not found
head: cannot open `samp.csv' for reading: No such file or directory
sed: can't read samp.csv: No such file or directory
tail: cannot open `samp.csv' for reading: No such file or directory
tac: cannot open `samp.csv' for reading: No such file or directory
split: cannot open `samp.csv' for reading: No such file


Last edited by azherkn3; 02-04-2014 at 05:52 AM.. Reason: adding code tags
# 2  
Old 02-03-2014
1. You must have spaces on both side of opening and closing square brackets.

Code:
if [ $run -eq 10 ]; then


2. Make sure 'samp.csv' exists, Probably it exists in your current directory. Provide full path of all the files so that it can be read with-in cron.


3. What are you trying to achieve with 1=1000?
This User Gave Thanks to clx For This Post:
# 3  
Old 02-03-2014
the file exists but it is tellling unable to read
1=1000 i am spliting it 1000 times
if u see
Code:
 
split $1 samp.csv


Last edited by azherkn3; 02-03-2014 at 07:48 AM..
# 4  
Old 02-03-2014
Quote:
Originally Posted by azherkn3
the file exists but it is tellling unable to read
Exists where? IS it exist in the $HOME of the cron user?
As I said earlier please provide full path of the path (starts with "/").




Quote:
Originally Posted by azherkn3

1=1000 i am spliting it 1000 times
You can't use absolute numbers as the variables name. Alphanumeric and underscore allowed but must not starts with number.

Code:
a1=1000 #allowed
1=1000 # not allowed
1a=1000 #not allowed
_a1=1000 #allowed

This User Gave Thanks to clx For This Post:
# 5  
Old 02-03-2014
yup it works fine thanks guys

but the problem here is my
Code:
 a.log

file doe not increment the counter every time the cron is executing what might be the reason
# 6  
Old 02-03-2014
Which shell are you using? Has the command executed successfully?
Try running the script manually and check whether the value of $run is being incremented correctly.

If you face any issues, Try replacing let run=($(cat a.log)+1) with run=$(( $(cat a.log)+1 ))
This User Gave Thanks to clx For This Post:
# 7  
Old 02-03-2014
bourne shell clx
removing let and using the code you mentioned is not working clx

when i removed
Quote:
let
and checked it displaying as only
Quote:
0+1
its not incrementing each time the cron is executing what might be the problem clx

Last edited by azherkn3; 02-03-2014 at 10:16 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run a shell script in a loop with max number of threads

hi guys. i have a question for you i have a one file and inside this file there are 1000 lines and each line is a linux command running this commands takes long time so i want to create one bash script and run this lines in a loop with max number of threads for example i want to run... (2 Replies)
Discussion started by: avtaritet
2 Replies

2. Shell Programming and Scripting

How to use counter to run the script to limit number?

I want to run my shell script to the limit number.Suppose I know in advance that MAX=5 then I want that my script run 5 times only.Something like below$ vi testingMAX=5COMMAND="ssh -l stpuser VHLDVWSAD001 /projects/st/utils/deploy/deployall.sh >/dev/null 2>&1 &" ; sleep 20;count=0while... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

3. Shell Programming and Scripting

Pausing between two executions in a shell script

HI, Please help me on this. I have to execute 100 scripts which i have redirected in to a file . I want to pause the script after first execution and once i say enter key word it has to go to next execution. My looks like for RUNFILES in `cat ${SOURCEFILES}/scripts` do echo $RUNFILES; ... (1 Reply)
Discussion started by: srichunduru
1 Replies

4. UNIX for Dummies Questions & Answers

Cannot run crontab :1: bad minute error

Hi can any one help me out. while running crontab , m getting error bad minute time.. how to resolve this error. i created 1 txt file a.cron mirrordir -vm \home\t \homet1 & i saved it. then i created a crontab file ..with crontab -e & i added a line in it. * 1 * * * \root\a.cron & i save... (2 Replies)
Discussion started by: unxdost114
2 Replies

5. Shell Programming and Scripting

tcsh: not run script (if: Badly formed number)

Hello I have Linux Debian & tcsh shell. My mini script not run :(. Startup script displays a message: user@host:dir% ./test if: Badly formed number. script: #!/bin/tcsh -f #script check size files systems set x = `df -h /usr | tail -n1 | awk '{ print( $5 ); }'` set y = 60% if ($x... (5 Replies)
Discussion started by: moskovets
5 Replies

6. AIX

My script didn't run every run every minute at cronjob

In my cronjob, I would like to schedule my script.sh to run every minutes. I crontab -e and have in line below but it didn't seems to run at all. * * * * * script.sh When I run it manually, I can run it. Is that anything wrong with the above line? If I change it to something like below,... (4 Replies)
Discussion started by: ngaisteve1
4 Replies

7. Shell Programming and Scripting

Ksh Script to get the start minute of n number of process

How can i write a script.? which lists all X process and gets the start minute of each of them. thanks (1 Reply)
Discussion started by: Anteus
1 Replies

8. Shell Programming and Scripting

run script 1 minute interval without CronTab

I am using Solaris 9. I wish to run my script every 1 minute inteval. Though i can run it using below entry in crontab. * * * * /export/home/username/script/file_exist_&_run.sh in short above script will check whether a specific file exist in a directory. If it found it will inovke another... (10 Replies)
Discussion started by: thepurple
10 Replies

9. Programming

how can i run a process for a whole minute?

here's the problem, i have two processes that i need to run and both process should be run at a total of 1 minute each. how do i do that? and one more here's what the processes do: the 1st process show the '+" sign infinitely while the 2nd process displays the "-" infinitely. how could i count the... (1 Reply)
Discussion started by: kelogs1347
1 Replies

10. Shell Programming and Scripting

Terminate session on completing script

Hai all.. How do i terminate my telnet session automatically when my java applicatiion exits. i have a file run which executes my java application and takes care of all class and library path settings prior to the execution. I would like to terminate my session when my application exits. The... (4 Replies)
Discussion started by: deepsteptom
4 Replies
Login or Register to Ask a Question