I am sure i made a mistake some where, but not able to find that..
Your pasted scrpit code code seems to be missing the first few lines, but this is probably a typo too. Also your line:
misses a double quote, but that is probably a typo too.
Your real mistake is not to understand the "scope" of variables. Variables are always bound to the context they are defined in. Outside of this context, they do not exist. (It is possible to overrule this somewhat by using "export", but let us set this aside for the moment.)
consider the following script:
A main routine is executed. This routine calls another routine, "subfunc1()" and - upon entering this function - the context changes. When leaving this function, the context changes again and the original variables are restored.
Now, in light of this, check where "iCurrDay" is defined. You will see that outside the function pCheckAttempts() the value of "iCurrDay" is not defined because the variable inside this function - is INSIDE! And nowhere else!
You might want to play around with the example script above, defining and displaying additional variables at various places, to get comfortable with the concept. In fact this is a very powerful device. With this it is possible to write subfunctions which do not care about their surroundings. (In fact it is strongly advised to write every function this way.) This is part of a general programming concept called "encapsulation". This means that in a program every subfunction should be completely independent of all the other parts in its own operation.
For instance, it is possible to do this (here we come back to the "export" keyword):
Run this once as it is and then after uncommenting the line "export othervar" and notice the effect. After exporting the variable it becomes visible in subfunc1() too. Do such a thing only with extreme caution, because now the function becomes dependent on something outside. It would not be possible any more to take it out of the script and use it in another script.
I want to create an automated script which is called by another maually executed script.
The condition is that the no one should be able to manually execute the automated script.
The automated script can be on the same machine or it can be on a remote machine.
Can any one suggest a check in the... (1 Reply)
Hi ,
I have a date parameter passed in YYYYMMDD format , how can I check whether it is Sat or Sun on Solaris box , as we can do the same easily on linux box by using date -d YYYYMMDD '+a' .
Any pointres will be really helpful . (5 Replies)
Hi,
i have a script 'a.sh' that should be called only by certain scripts like b.sh, c.sh
Inside a.sh, how can i determine
1) if this script was run directly from command prompt (or scheduler)
2) if called via other scripts?
Is there an easy way to get parent process name (not just pid),... (2 Replies)
Hello,
I wanted to run one of my shell script for every sunday at 5PM.
Here is the crontab entry i am using..
00 17 * * 0 /inventory/update.sh > /inventory/update.log 2>&1
The job is not kicking on sunday at the specified time.. Am i missing anthing?
Any help is appreciated... (2 Replies)
I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
I was to schedule a script in a crontab after every 15 days specically on every 2nd Sunday.
I know that i can schedule on basis of weekdays, but can it be done by skipping in between???:wall: (5 Replies)
Hi,
I need to create a autosys job which will run on every sunday at 7:30 AM NY time for each 10 min interval of time.
days_of_week: su
start_mins: 0,10,20,30,40,50
run_window:"07:30"
Is it fine? Please help
Thanks,
Anup (2 Replies)
Hello,
I'm looking for a bash script, that I will run from cron, that executes a php script. After 5 minutes that the php script is executed, the bash script, must check a value in a text file /public_html/check.txt
if check.txt = 0 the script will stop, if check.txt is not = 0 it must... (0 Replies)
Hi all,
I have a script that can be run via cron or via the command line.
Is there any way that I can place something on the script to be able to distinguish/differentiate whether the script was run via a user in the command line or whether it was run from the cron? (3 Replies)
Hi ALL,
I have been testing this script to run for every last Sunday of the month,looks like month which have 5 sunday (july 2016 )is not passing this and failing every time.
Here is what I am using,
current_date=31
echo " CURRENT DAY -> $current_date"
if
... (2 Replies)