Run script every minute and terminate after specified number of executions

when it runs and look at my acron.log file it generates an error as below

/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
  1. You must have spaces on both side of opening and closing square brackets.
if [ $run -eq 10 ]; then
  1. 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.

  2. What are you trying to achieve with 1=1000 ?

1 Like

the file exists but it is tellling unable to read
1=1000 i am spliting it 1000 times
if u see

 
split $1 samp.csv

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 "/").

You can't use absolute numbers as the variables name. Alphanumeric and underscore allowed but must not starts with number.

a1=1000 #allowed
1=1000 # not allowed
1a=1000 #not allowed
_a1=1000 #allowed
1 Like

yup it works fine thanks guys

but the problem here is my

 a.log 

file doe not increment the counter every time the cron is executing what might be the reason

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

1 Like

bourne shell clx
removing let and using the code you mentioned is not working clx

when i removed

and checked it displaying as only

its not incrementing each time the cron is executing what might be the problem clx

Don't have it started by cron every minute. Run it once, execute a loop 10 times, sleep for not quite a minute in that loop, and exit gracefully.

And, why don't you give us a broader picture of what you want to achive? We might be able to help you better, then, instead of supplying bits and pieces here and there...

thanks

If I understand what is going on in this thread, you have changed references in your script to use absolute pathnames when your read and write samp.csv, but it sounds like you are not using an absolute pathname when you read and write a.log. Unless you add a cd command at the start of your script to move into the directory where all of these files reside, you have to use absolute pathnames in all references to all input and output files.

How are you initializing the contents of /full/path/to/a.log?

thanks

Did you really do what clx suggested? Or did you only remove the let?
Here is another one

read run < a.log
echo $(( $run + 1 )) > a.log

It's nearly always best to use the absolute path name in scripts, for all filenames, including commands.

First of all, if you don't use a full path, then it's possible another file can be executed that is in the search path; and this can cause numerous problems, including security issues.

Second, if you refuse (for some odd reason), to use the full path name, you should define your search path explicitly in the script, for the same reasons.

In this example, the poster is writing from cron as a user that he has not defined (for us). It's possible he could be running it as a root crontab.

The original poster should rewrite the script using the full path to all files (commands, logs, input files, etc.) and he should inform what user crontab is running this script.

He should also list each file that is read and written to with ls -l so we can see the permissions of the files.

i think it is best when working the problems to get the correct and full information instead of just grasping at straws and pulling bits and pieces of information from the member with the problem.

The user will also learn more, I think, if we ask them to provide the right information up front, define his paths correctly (all paths), etc. .. in my view.

1 Like