Sponsored Content
Operating Systems Solaris Set script to run during specific times Post 302912136 by frum on Wednesday 6th of August 2014 07:02:09 AM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

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

8. 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

9. 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

10. 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
smcron(1M)						  System Administration Commands						smcron(1M)

NAME
smcron - manage jobs in the crontab database SYNOPSIS
/usr/sadm/bin/smcron subcommand [ auth_args] -- [subcommand_args] DESCRIPTION
The smcron command manages jobs in the crontab(1) database. subcommands smcron subcommands are: add Adds a job to the crontab(1) database. To add a job, the administrator must have the solaris.jobs.user authorization. To add a job to another user's crontab file, the administrator must have the solaris.jobs.admin authorization. delete Deletes a job from the crontab(1) database. To delete a job, the administrator must have the solaris.jobs.user authoriza- tion. To delete a job from another user's crontab file, the administrator must have the solaris.jobs.admin authorization. list Lists one or more jobs in the crontab(1) database. To list all jobs, the administrator must have the solaris.jobs.user authorization. To list a job in another user's crontab file, the administrator must have the solaris.jobs.admin authoriza- tion. No authorization is needed to list a user's own jobs. modify Modifies a job in the crontab(1) database. To modify a job, the administrator must have the solaris.jobs.user authoriza- tion. To modify a job in another user's crontab file, the administrator must have the solaris.jobs.admin authorization. OPTIONS
The smcron authentication arguments, auth_args, are derived from the smc(1M) arg set and are the same regardless of which subcommand you use. The smcron command requires the Solaris Management Console to be initialized for the command to succeed (see smc(1M)). After reboot- ing the Solaris Management Console server, the first Solaris Management Console connection might time out, so you might need to retry the command. The subcommand-specific options, subcommand_args, must come after the auth_args and must be separated from them by the -- option. auth_args The valid auth_args are -D, -H, -l, -p, -r, and -u; they are all optional. If no auth_args are specified, certain defaults will be assumed and the user may be prompted for additional information, such as a password for authentication purposes. These letter options can also be specified by their equivalent option words preceded by a double dash. For example, you can use either -D or --domain with the domain argu- ment. -D | --domain domain Specifies the default domain that you want to manage. smcron accepts only file for this option. file is also the default value. The file default domain means that changes are local to the server. Toolboxes can change the domain on a tool-by-tool basis; this option specifies the domain for all other tools. -H | --hostname host_name:port Specifies the host_name and port to which you want to connect. If you do not specify a port, the system connects to the default port, 898. If you do not specify host_name:port, the Solaris Management Console connects to the local host on port 898. You may still have to choose a toolbox to load into the console. To override this behavior, use the smc(1M) -B option, or set your console preferences to load a "home toolbox" by default. -l | --rolepassword role_password Specifies the password for the role_name. If you specify a role_name but do not specify a role_password, the system prompts you to sup- ply a role_password. Passwords specified on the command line can be seen by any user on the system, hence this option is considered insecure. -p | --password password Specifies the password for the user_name. If you do not specify a password, the system prompts you for one. Passwords specified on the command line can be seen by any user on the system, hence this option is considered insecure. -r | --rolename role_name Specifies a role name for authentication. If you do not specify this option, no role is assumed. -u | --username user_name Specifies the user name for authentication. If you do not specify this option, the user identity running the console process is assumed. -- This option is required and must always follow the preceding options. If you do not enter the preceding options, you must still enter the -- option. subcommand_args For the time-related subcommands described below, -m, -M, -t, and -w, you can enter multiple arguments, separated only by commas. smcron will construct crontab entries appropriate for your arguments. See EXAMPLES. Note: Descriptions and other arg options that contain white spaces must be enclosed in double quotes. o For subcommand add: -c command Specifies the command that you want to run. -h (Optional) Displays the command's usage statement. -m day_of_month (Optional) Specifies the day of the month you want to run the job. Valid values are 1-31. If you specify both -t and -m options, the job executes one day per month at the time specified by -t. -M month (Optional) Specifies the month that you want to run the job. Valid values are 1-12. If you specify both -t and -M options, the job executes during the specified month at the time specified by -t. -n name Specifies the unique name of the job. -o owner (Optional) Specifies the user name that is the owner of the job. If you do not specify this option, the user name specified by the -U option is assumed. -t time_of_day Specifies the time (in hh:mm) that you want to execute the command. If no other time-related options are specified (-m, -M, or -w), the job executes every day at the time specified by -t. If you specify both -t and -w options, the job executes one day per week at the time specified by -t. If you specify both -t and -m options, the job executes one day per month at the time specified by -t. If you specify both -t and -M options, the job executes each day during the specified month at the time specified by -t. -w day_of_week (Optional) Specifies the day of the week you want to execute the command. Valid values are as follows: o 0=Sunday o 1=Monday o 2=Tuesday o 3=Wednesday o 4=Thursday o 5=Friday o 6=Saturday If you specify both -t and -w options, the job executes one day per week at the time specified by -t. o For subcommand delete: -h (Optional) Displays the command's usage statement. -n name Specifies the unique name of the job. -o owner (Optional) Specifies the user name that is the owner of the job. If you do not specify this option, the user name specified by the -U option is assumed. o For subcommand list: -f n|s|v (Optional) Specifies the format of the output. See EXAMPLES for examples of each output type. o n -- Displays the data in native format, as it appears in the crontab(1) database. o s -- Default format. Displays the data in summary format. o v -- Displays the data in verbose format. -h (Optional) Displays the command's usage statement. -o owner (Optional) Lists all jobs for the specified owner (user name). If you do not specify this option, all jobs in the crontab(1) data- base are listed. o For subcommand modify: -c command (Optional) Specifies the command that you want to run. -h (Optional) Displays the command's usage statement. -m day_of_month (Optional) Specifies the day of the month you want to run the job. Valid values are 1-31. If you specify both -t and -m options, the job executes one day per month at the time specified by -t. -M month (Optional) Specifies the month that you want to run the job. Valid values are 1-12. If you specify both -t and -M options, the job executes during the specified month at the time specified by -t. -n name Specifies the current unique name of the job. -N new_name (Optional) Specifies the new unique name of the job. -o owner (Optional) Specifies the user name that is the owner of the job. If you do not specify this option, the user name specified by the -U option is assumed. -O new_owner (Optional) Specifies the new owner of the job. -t time_of_day (Optional) Specifies the time (in hh:mm) that you want to execute the command. If no other time-related options are specified (-m, -M, or -w), then the job executes every day at the time specified by -t. If you specify both -t and -w options, the job executes one day per week at the time specified by -t. If you specify both -t and -m options, the job executes one day per month at the time specified by -t. If you specify both -t and -M, then the job executes each day during the specified month at the time speci- fied by -t. -w day_of_week (Optional) Specifies the day of the week you want to execute the command. Valid values are as follows: o 0=Sunday o 1=Monday o 2=Tuesday o 3=Wednesday o 4=Thursday o 5=Friday o 6=Saturday If you specify both -t and -w options, the job executes one day per week at the time specified by -t. EXAMPLES
Example 1: Adding a Job The following adds a new job, owned by root, that removes the old log files from /tmp daily at 1:30 AM. ./smcron add -H myhost -u root -p mypassword -- -n "Remove old logs" -t 1:30 -c "rm /tmp/*.log" -o root Example 2: Deleting a Job The following deletes the job Remove old logs owned by root: ./smcron delete -H myhost -u root -p mypassword -- -n "Remove old logs" -o root Example 3: Listing Jobs in Native Format The following lists all jobs in native, or crontab(1), format: ./smcron list -H myhost -u root -p mypassword -- -f n MINUTE HOUR DATE MONTH DAY COMMAND 10 3 * * * /usr/sbin/logadm 15 3 * * 0 /usr/lib/fs/nfs/nfsfind 1 2 * * * [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1 30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean Example 4: Listing Jobs in Standard Format The following lists all jobs owned by lp in standard format: ./smcron list -H myhost -u root -p mypassword -- -f s -o lp NAME::OWNER::SCHEDULE::COMMAND NoName_1765663371::lp::Weekly on Sundays at 3:13 AM::cd /var/lp/logs; if [ -f requests ]; then if [ -f requests.1 ]; then /bin/mv requests.1 requests.2; fi; /usr/bin/cp requests requests.1; > requests; fi NoName_512822673::lp::Weekly on Sundays at 4:15 AM::cd /var/lp/logs; if [ -f lpsched ]; then if [ -f lpsched.1 ]; then /bin/mv lpsched.1 lpsched.2; fi; /usr/bin/cp lpsched lpsched.1; >lpsched; fi Example 5: Listing jobs in verbose format The following lists all jobs in verbose format: ./smcron list -H myhost -u root -p mypassword -- -f v NAME::OWNER::SCHEDULE::NEXT_RUN::STATUS::COMMAND NoName_1075488942::root::Advanced::::Finished on Feb 10 3:10 with code 1 ::/etc/cron.d/logchecker databackup::root::Weekly on Sundays at 3:10 AM::3/19/00 3:10 AM ::Finished on Sep 19 3:10::/usr/lib/newsyslog runlog::root::Daily at 2:01 AM::3/14/00 2:01 AM::Finished on Feb 11 2:01 AM::/usr/sbin/rtc Example 6: Changing a Job The following modifies the job Remove old logs owned by root to execute daily at 2:00 AM: ./smcron modify -H myhost -u root -p mypassword -- -n "Remove old logs" -o root -t 2:00 Example 7: Specifying Multiple Time Arguments smcron allows you to specify a range of times for all of its time-related subcommands, -m, -M, -t, and -w. For example, the following com- mand: # smcron add -u root -p xxxx -- -n cronjob1 -w 1-4,5 -t 12:00,13:15,14:30 -c ls ...creates the following entry in crontab: 0,15,30 12,13,14 * * 1,2,3,4,6 ls #cronjob1 This job would run on Monday through Thursday and Saturday at the following times: 12:00 12:15 12:30 13:00 13:15 13:30 14:00 14:15 14:30 ENVIRONMENT VARIABLES
See environ(5) for a description of the JAVA_HOME environment variable, which affects the execution of the smcron command. If this envi- ronment variable is not specified, the /usr/java location is used. See smc(1M). EXIT STATUS
The following exit values are returned: 0 Successful completion. 1 Invalid command syntax. A usage message displays. 2 An error occurred while executing the command. An error message displays. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWmga | +-----------------------------+-----------------------------+ SEE ALSO
crontab(1), cron(1M), smc(1M), attributes(5), environ(5) NOTES
The timezone of the cron daemon sets the system-wide timezone for cron entries. This, in turn, is by set by default system-wide using /etc/default/init. If some form of daylight savings or summer/winter time is in effect, then jobs scheduled during the switchover period could be executed once, twice, or not at all. SunOS 5.10 24 Mar 2003 smcron(1M)
All times are GMT -4. The time now is 10:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy