- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Need help with scripting.
Operating System - HP-UX
1753776
Members
7453
Online
108799
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО05-13-2009 03:05 AM
тАО05-13-2009 03:05 AM
Hi,
I have the following script for purging & archive old files from tmp. When I manually run the script, it runs fine & give archive.gz file.
But when I schedule the same script to run in cron, it produces a 0 bytes file.
Can somebody please help what is going wrong when cron runs the same script.
#!/usr/bin/sh
set -u
SEARCH=/tmp/xyz
GZDIR=/tmp/xyz/archive
GZFILE=${GZDIR}/arch_$(date +%Y%m%d).gz
cd ${SEARCH} || exit 1
FILES=$(find . -type f -mtime +10)
[ -z "${FILES}" ] && { echo "no files older than 10-days"; exit 1; }
tar -cvf - ${FILES} | gzip - > ${GZFILE}
find ${GZDIR} -type f -name "*.gz" -mtime +10 -exec rm {} +
#rm ${FILES} #...to remove what you archived...
exit 0
I have the following script for purging & archive old files from tmp. When I manually run the script, it runs fine & give archive.gz file.
But when I schedule the same script to run in cron, it produces a 0 bytes file.
Can somebody please help what is going wrong when cron runs the same script.
#!/usr/bin/sh
set -u
SEARCH=/tmp/xyz
GZDIR=/tmp/xyz/archive
GZFILE=${GZDIR}/arch_$(date +%Y%m%d).gz
cd ${SEARCH} || exit 1
FILES=$(find . -type f -mtime +10)
[ -z "${FILES}" ] && { echo "no files older than 10-days"; exit 1; }
tar -cvf - ${FILES} | gzip - > ${GZFILE}
find ${GZDIR} -type f -name "*.gz" -mtime +10 -exec rm {} +
#rm ${FILES} #...to remove what you archived...
exit 0
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-13-2009 03:12 AM
тАО05-13-2009 03:12 AM
Solution
Whenever we come across a script that runs fine from the command line yet does not work from cron, it is nearly always because of the sparse environment provided by cron. Check the man pages and you will find that the PATH for cron is minimal, and many environment variables are not set. The first thing I would do is make sure you either put a PATH statement in the beginning of your script or use full path names for all your commands (tar=/usr/bin/tar, find=/usr/bin/find, etc.)
Pete
Pete
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-13-2009 03:30 AM
тАО05-13-2009 03:30 AM
Re: Need help with scripting.
Silly me, thanks a lot Pete.
Putting the full path names solved my problem.
Thanks - I have assigned points.
Putting the full path names solved my problem.
Thanks - I have assigned points.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-13-2009 06:34 PM
тАО05-13-2009 06:34 PM
Re: Need help with scripting.
>Putting the full path names solved my problem.
It seems that gzip was the only one that needed it.
>Pete: tar=/usr/bin/tar, find=/usr/bin/find, etc.)
None of these are really needed, they are in the default cron PATH.
It seems that gzip was the only one that needed it.
>Pete: tar=/usr/bin/tar, find=/usr/bin/find, etc.)
None of these are really needed, they are in the default cron PATH.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP