Set script to run during specific times


 
Thread Tools Search this Thread
Operating Systems Solaris Set script to run during specific times
# 1  
Old 08-06-2014
Set script to run during specific times

Hi all,

I have this script which sends mail whenever the system is down. It works fine. Normally the system is down from 21 00 to 21 30 from Monday to Saturday and from 21 00 on Sunday to Monday 06 00 for maintenance. So I want the below script to run only when the system is up, i.e outside the times I mentioned. How can I do this in the script or I need to set it in the crontab? How can I set it in the crontab?

Code:
#!/usr/bin/ksh
if [[ `ps -ef|grep dw.sap|grep userprd|wc -l` -lt 3 ]]; then
        mailx -s "PRD is down!" helpdesk@klm-ltd.org < /dev/null
fi


Moderator's Comments:
Mod Comment Please use CODE tags to show your code, input & output/errors

Last edited by rbatte1; 08-06-2014 at 08:20 AM.. Reason: Added CODE tags
# 2  
Old 08-06-2014
There are some simple tests using the date command that will get you the information to make those decisions in the code. If you want to do it in cron, then you will need to set up several records:-
  • Monday from 6am
  • Tuesday-Sunday from midnight to 9pm
  • Tuesday-Saturday from 9:30pm to midnight
It all gets a bit messy.


What have you tried so far?



Please wrap code and data input/output in CODE tags, like this:-
Quote:
[CODE]This is my code[/CODE]
to produce the following (fixed character width, space respected):-
Code:
This is my code

Not only does it make posts far easier to read, but CODE and ICODE sections respect multiple space and have fixed width characters, which is important for easily seeing input/output requirements.



Regards,
Robin
# 3  
Old 08-06-2014
You might try something like:
Code:
#!/usr/bin/ksh
IAm=${0##*/}
read d hm <<-EOF
	$(LC_ALL=C date '+%a %H%M')
EOF
hm=${hm#0}	# Strip leading zero from hour and minute, if present.
case $d in
(Sun)	if [ $hm -ge 2100 ] || [ $hm -le 600 ]
	then	down=1
	fi;;
(*)	if [ $hm -ge 2100 ] && [ $hm -le 2130 ]
	then	down=1
	fi;;
esac
if [ "$down" == 1 ]
then	printf '%s: Exiting: Scheduled downtime.\n' "$IAm"
else if [ `ps -ef|grep dw.sap|grep userprd|wc -l` -lt 3 ]; then
        mailx -s "PRD is down!" helpdesk@klm-ltd.org < /dev/null
fi

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 job between times else run later

Hi guys, I have written a script that waits for a trigger file. Then checks the time of the trigger. if the trigger finished between 8pm and midnight then runs a job. else it waits till 1am then runs a different job. I am still very new to scripting so any suggestions to improve my... (4 Replies)
Discussion started by: twinion
4 Replies

2. Shell Programming and Scripting

Script to run commands at a specific time.

Hello All, I have written a script which which is working fine to a certain logic of it. But i want a part of the script to run two commands at 00:10 hrs every day. These two command are 1. rm -rf /path/to/folder 2. mail the content of a file. How do i achieve this. Thanks. ... (4 Replies)
Discussion started by: Siddheshk
4 Replies

3. Shell Programming and Scripting

shell script that will run for a specific date

Hi, I have these changes needed to modify a shell script that will run on a specific date of a month, below pseudocode, appreciate any answers..thanks.. if date of the month is 26th then ..event 1 fi if date of the month is 26th and month are MAR,JUN,SEP,DEC then ..event2 ... (7 Replies)
Discussion started by: sonja
7 Replies

4. Shell Programming and Scripting

Run .command at specific times

Okay so I've got a command to start my java server up, but I want it to start at say 8:00AM and then stop at 11:00PM. In order to stop it I have to type stop and press enter in the terminal. I've been trying to get this to work and I'm having no luck. Here's my command: #!/bin/bash cd "`dirname... (2 Replies)
Discussion started by: JustChillin1414
2 Replies

5. Shell Programming and Scripting

Counting script how many times it run?

i should use this script runs how many times before ? how can i do_? (3 Replies)
Discussion started by: utoptas
3 Replies

6. Shell Programming and Scripting

Shell script to run x times

Hi, First i need to cd to this directory $SWDIR/util Second i need to run the following either 4 times or 20 times ./swadm add_process 1 BG Y how can i put this in a script which should ask for user input on how many times you want to run this Thanks, (5 Replies)
Discussion started by: lookinginfo
5 Replies

7. Shell Programming and Scripting

run a script to set a globle varible?

Hi, My original shell is csh, I don't likw it, so I have to run bash every time after I login, the problem is I have a script like export PLOG=$1, every time I run the script under bash, the PLOG won't be set, I know I can use source to set the PLOG, is there any other way to do it? ... (3 Replies)
Discussion started by: laopi
3 Replies

8. Shell Programming and Scripting

Need to run same script multiple times in parallel

Hi all, I have a requirement in which a script invokes a Java program. Lets say script ABC invokes a java program with cfg file a parameter. This script takes 10 minutes to execute . Like this ineed to run the program 10 times meaning 100 minutes if i do it sequentially. If i open... (2 Replies)
Discussion started by: rahman_riyaz
2 Replies

9. Shell Programming and Scripting

Need help howto make a script for Set SNOOP run for 5 minutes

Hi all, I want to monitoring my interface every 6 hours where i want to run snoop command to capture all packet through the interface, so i want running snoop then snoop will run for 5 minutes after that snoop stop then will start again after 6 hours than run for 5 minutes again. thereis any... (9 Replies)
Discussion started by: tindasz
9 Replies

10. Shell Programming and Scripting

set schedule to run a script at background while logout

Hi, How can I run a script at 9:00am and 6:00pm everyday? Can I run it at background while I logout my account? Please help!! Many Thanks!! (1 Reply)
Discussion started by: happyv
1 Replies
Login or Register to Ask a Question