- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Variables in crontab
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2009 04:14 AM
тАО03-27-2009 04:14 AM
Variables in crontab
it looks like the following doesn't work:
=====begin crontab======
ORACLE_HOME=/very/long/path/to/oracle/10g/db
1 2 * * * $ORACLE_HOME/scripts/run1.sh
1 2 * * * $ORACLE_HOME/scripts/run2.sh
#[...]
1 2 * * * $ORACLE_HOME/scripts/run1000.sh
=====end crontab======
Does anybody know if there is any way to define my own variables to be used in crontab entries? I wouldn't like to take advantage of external files with variables definitions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2009 04:17 AM
тАО03-27-2009 04:17 AM
Re: Variables in crontab
Put the variables inside the script and schedule the script in crontab.
Or use the absolute path in the cron entry.
Ganesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2009 04:20 AM
тАО03-27-2009 04:20 AM
Re: Variables in crontab
Also,you can create an environmental file to have all the variables and you can call this .env in your script or both like
0 1 * * * (/home/test/.env /home/test/run.sh)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2009 04:23 AM
тАО03-27-2009 04:23 AM
Re: Variables in crontab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2009 04:33 AM
тАО03-27-2009 04:33 AM
Re: Variables in crontab
If you don't want to code necessary variables in your script and/or you don't want to source (read) another file of variables when you execute your script, you could do:
# cat /tmp/mysh
#!/usr/bin/sh
echo "${WHO} --- ${WHY}"
exit 0
...with a 'crontab' entry like:
* * * * * ( export WHO="me"; export WHY="I said so"; /tmp/mysh )
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2009 04:38 AM
тАО03-27-2009 04:38 AM
Re: Variables in crontab
> path to the script?
Then you may be doomed.
> I don't want to use
> absolute as it is a kind of dynamic one.
Yes, but if cron has a way to get the value
of your variable, then it's a mystery to me.
I'd say that you need to have a script in
some fixed, known location, so that cron can
find it. That script can then do anything
dynamic which you need to do.
Of course, how you'll choose to inform that
script about the dynamic stuff is still an
open question, but many things are possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2009 06:10 AM
тАО03-27-2009 06:10 AM
Re: Variables in crontab
Use symbolic links.
First make a directory for the links in some convenient path:
mkdir /usr/local/cronscripts
Then link all the scripts to the directory:
ln -s /very/long/path/to/oracle/10g/db/scripts/run*.sh /usr/local/cronscripts
After this, you should be able to setup your crontab entries like this:
1 2 * * * /usr/local/cronscripts/run1.sh
...etc...
Of course, you should keep in mind that the ORACLE_HOME variable is not defined when the scripts are executed, unless the scripts themselves handle that.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2009 06:10 AM
тАО03-27-2009 06:10 AM
Re: Variables in crontab
ORACLE_HOME=/very/long/path/to/oracle/10g/db
1 2 * * * $ORACLE_HOME/scripts/run1.sh
1 2 * * * $ORACLE_HOME/scripts/run2.sh
#[...]
1 2 * * * $ORACLE_HOME/scripts/run1000.sh
=====end crontab======"
that can't be done...
you might consider making a symbolic link, like /oracle_home and point at your long path, so that crontab entries become
/oracle_home/scripts/run1.sh
then, as suggested previously, have your scripts source whatever environment files are necessary.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2009 09:31 AM
тАО03-27-2009 09:31 AM
Re: Variables in crontab
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2009 03:31 PM
тАО03-27-2009 03:31 PM
Re: Variables in crontab
You could have a template crontab file and then write a sed script to change your "variables", then submit to crontab.