Operating System - HP-UX
1825667 Members
4528 Online
109686 Solutions
New Discussion

running commands at selected time

 
SOLVED
Go to solution
Ahmed M. AlShafiy
Regular Advisor

running commands at selected time

how can i run a command that is owned by another user than the root at a selected time.

i have a commands under the application admin to stop the oracle application and another commands under the database user to stop and restart the oracle database.

and after that i want to select a time to run a backup.
21 REPLIES 21
Muthukumar_5
Honored Contributor

Re: running commands at selected time

You can choose schedular(s) like crontab or at to start commands at required time. Or else you can make scripting to check time and sleep for the rest of the time.

--
Muthu
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: running commands at selected time

write down script for start and stopping oracle application and as well as backup. Put the crontab with crontab -e using that user.

You have to use sudo to run the application from that user without using password.

--
Muthu
Easy to suggest when don't know about the problem!
Ahmed M. AlShafiy
Regular Advisor

Re: running commands at selected time

sorry but i'm a new with HP-UX can you help me with the steps to do it?


:(
Joseph Loo
Honored Contributor

Re: running commands at selected time

hi,

u may use "cron" or "at" to schedule the job.

for root to run the script as another user:

# su - -c <script>

regards.
what you do not see does not mean you should not believe
Devender Khatana
Honored Contributor

Re: running commands at selected time

Hi,

The process of executing a command at a particular time can be done by both at and cron. But best to do for this sort of scenario will be to create a script which checks for the status of completion of first command and only after successful completion of the first command executes the later part.

HTH,
Devender
Impossible itself mentions "I m possible"
Arunvijai_4
Honored Contributor

Re: running commands at selected time

Hi,

You can write your own script and put it in crontab or at to run at selected time.

# man crontab
# man at

for more details.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Cem Tugrul
Esteemed Contributor

Re: running commands at selected time

Selam Ahmed,
"at" or "crontab" are for running jobs
automatically.Normally "at" is using for to run only 1 ,cron is for to run a processes,script more than 1 as permanently

Good Luck,
Our greatest duty in this life is to help others. And please, if you can't
Muthukumar_5
Honored Contributor

Re: running commands at selected time

Are you able to stop / start / take backup from command line. Try to take those command and,

login with that user which you want to run the commands,

crontab -e

and use the format of,

minute hour monthday month weekday command

Change this format to suit your requirement. My previous reply is having more examples.

--
Muthu
Easy to suggest when don't know about the problem!
Cem Tugrul
Esteemed Contributor
Arunvijai_4
Honored Contributor

Re: running commands at selected time

Some threads for your reference,

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=821853
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=31119

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Yogeeraj_1
Honored Contributor

Re: running commands at selected time

hi,

First of all you must create a script for each of the following operations:
a. Stop the Oracle Application
b. Shutdown the Oracle database
c. Startup of the Oracle Database
d. Perform a database backup
e. Startup of the Oracle Application

(nb. a & e can be one script as well as b &c.

You can then use "cron" or "at" to schedule the execution at the required times.

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Ahmed M. AlShafiy
Regular Advisor

Re: running commands at selected time

we have the scripts for shutting down the application and the database:
1- ./stopappl for shutdown the application.
2- ./stoporadb for shutdown the database.

so if i want to run this to scripts at 18:00pm evrey day exept weekends.

what is the full command to do it?

remark: ./stopappl under applmgr user and the ./stoporadb under oracle user.

Arturo Galbiati
Esteemed Contributor

Re: running commands at selected time

Hi,
you should put in place something like this:

###########################################################
# -
###########################################################
###########################################################
# BACKUP ON ....... ..:.. AM ... - ..: PM server time
###########################################################

# ---------------------------------------------------------
# Daily
# ---------------------------------------------------------
# minute hour monthday month weekday (0=Sunday) command
# 0-59 0-23 1-31 1-12 0-6
03 00 * * * crontab -l > file_cron
00 18 * * 1-5 stopappl >/tmp/stopapl.log 2>&1
10 18 * * 1-5 remsh $(hostname) -l oracle -n stoporadb >/tmp/stoporadb.log 2>&1

#eof


the stopradb is executed from the same user but connecting via remsh to oracle user.
Take care to load the profile and the right Oracle envirinemt in your script because crontab doesn't load the porofile for you.

HTH,
Art
Ahmed M. AlShafiy
Regular Advisor

Re: running commands at selected time

i have worte this command under root user for testing:

# cd /oracle

#at -f ./stopappl -m aalshafiy@host -t 0601041500.00

then i get a message to the root user:

bad time specification
James R. Ferguson
Acclaimed Contributor
Solution

Re: running commands at selected time

Hi:

The error message from 'at' is misleading. The problem is that the '-m' switch cannot have an argument with it. Instead of:

# at -f ./stopappl -m aalshafiy@host -t 0601041500.00

...you should have written:

# at -f ./stopappl -m -t 0601041500.00

Regards!

...JRF...
Ahmed M. AlShafiy
Regular Advisor

Re: running commands at selected time

the ./startappl it's a script and it's owned by oracle user not root and when i wrote under root user:

# cd /oracale

# at -f ./startappl -m -t 0601041610.00

i get this tow messages sent to root:

1- Cron: cron|at job completed: 1136416200.a 21091 a Wed Jan 4 16:10:02 MST 2006

2- Not a terminal
stty: : Not a typewriter
stty: : Not a typewriter

[3g
H H H H H H H H H
You are running addbctl.sh version 115.3


Starting the database NAS ...

SQL*Plus: Release 8.1.7.0.0 - Production on Wed Jan 4 16:10:00 2006

(c) Copyright 2000 Oracle Corporation. All rights reserved.

ERROR:
ORA-01031: insufficient privileges


ORA-01031: insufficient privileges

addbctl.sh: exiting with status 0


You are running addlnctl.sh version 115.2


Starting listener process NAS ...


addlnctl.sh: exiting with status 0
logout


*************************************************
Cron: The previous message is the standard output
and standard error of one of your at commands.



how i can run the job?
Sivakumar TS
Honored Contributor

Re: running commands at selected time

Dear Ahmed,

Some oracle scripts needs to be run only after logging in as oracle user, the .profile and the privilleges are customised for that.

Try

#su - -c < command_to_be_executed>

as the COMMAND in the "at" command.

With Regards,

Siva.
Nothing is Impossible !
Ahmed M. AlShafiy
Regular Advisor

Re: running commands at selected time

when i try to use at command under oracle user it give me this message:

you are not authorized to use at. Sorry.

how i can give authoriz to oracle user to use at and corntab to other users than root.
James R. Ferguson
Acclaimed Contributor

Re: running commands at selected time

Hi:

To authorize any user to be able to use 'at' or 'cron' you need to add the user to the appropriate 'allow' file:

# /var/adm/cron/at.allow
# /var/adm/cron/cron.allow

For example:

# cat /var/adm/at.allow
root
sys
adm
oracle

Regards!

...JRF...
Ahmed M. AlShafiy
Regular Advisor

Re: running commands at selected time

thanks all of you ...... :)