- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script to write to check the file in directory if ...
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
тАО09-30-2010 09:55 PM
тАО09-30-2010 09:55 PM
I have written the script for sending file to client through ftp but question over here is I want to run this script i.e. /script/FTPtansfer.ksh only when file is available in /ftpfile/outbox directory. I want to write another script so that it will call /script/FTPtansfer.ksh only when file is available in /ftpfile/outbox directory. And then I can schedule that script through cron to run every 15min and if file is available then it will run /script/FTPtansfer.ksh if not it wonтАЩt run the ftp transfer script. As I can directly schedule the FTP transfer script but the problem over here is every time this script will run it sent an automated e-mail and un-necessarily it will fill the inbox with mails even if file is not sent.
Please someone let me know how to write this script...
Thanks,
Narendra
Solved! Go to Solution.
- Tags:
- ftp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2010 01:44 AM
тАО10-01-2010 01:44 AM
SolutionIt's not fully clear what "file is available" means. If this means: file exist, it's readable, is not changed etc.
If to suggest that you may transfer the file when it is not changed, add to the beginning of the /script/FTPtansfer.ksh file the following:
DEALAY=30
if [ ! -s $FILENAME ]; then #File not found
exit
fi
NL=$(cat $FILENAME| wc -l) #Number of records
sleep $DELAY
NL1=(cat $FILENAME| wc -l)
if [ $NL != $NL1 ] ; then # File changed
exit
fi
#FTP the file
.....
In order to prevent unneeded mail messages ,
add the the cron entry >/dev/null 2>&1
e.g.
15/* * * * * /script/FTPtansfer.ksh >/dev/null 2>&1
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2010 02:48 AM
тАО10-01-2010 02:48 AM
Re: Script to write to check the file in directory if available then run the FTP transfer script.
You would need to ensure the file is ready and is not opened by another process.
You could check if any process has this file opened (with lsof). Another way is by amending the process/program producing the file : when the file is produced, create another file eg "ftpfileproduced.complete". You will have to manage this file and remove it before starting the process again.
Regards
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2010 03:51 AM
тАО10-01-2010 03:51 AM
Re: Script to write to check the file in directory if available then run the FTP transfer script.
The file would not change as it is generating from SAP application once the file is generated at Unix directory the file would not change.
Victor- Can it be possible to write another separate script instead so that I will schedule this script in cron without modifying the existing one i.e. /script/FTPtransfer.ksh. So that when this script runs every 15 min it will check for the file available if it is available then only it will run the /script/FTPtransfer.ksh
Thanks,
Narendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2010 08:29 AM
тАО10-01-2010 08:29 AM
Re: Script to write to check the file in directory if available then run the FTP transfer script.
> The file would not change as it is generating from SAP application once the file is generated at Unix directory the file would not change... Can it be possible to write another separate script instead so that I will schedule this script in cron without modifying the existing one i.e. /script/FTPtransfer.ksh.
Here's one way to accomodate this:
# cat ./monitorfile
#!/usr/bin/sh
typeset MYNAME=$(basename $0)
typeset MYFILE=/var/tmp/myfile #...change accordingly...
typeset MY_REF=/var/tmp/${MYNAME}.ref #...reflects name of this script...
[ -f "${MYFILE}" ] || exit 1
if [ ! -f "${MY_REF}" -o "${MYFILE}" -nt "${MY_REF}" ]; then
/script/FTPtransfer.ksh # launches your FTP script
touch ${MY_REF}
fi
exit 0
...Change the value of the 'MYFILE' variable to be the name of your file.
When run, the script tests to see if your file is newer (more recently updated) than a "reference" file's age. If it is, your FTP script is called, otherwise no action is taken.
As written, you would 'cron' this script.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2010 11:46 PM
тАО10-01-2010 11:46 PM
Re: Script to write to check the file in directory if available then run the FTP transfer script.
>And then I can schedule that script through cron to run every 15min and if file is available then it will run /script/FTPtansfer.ksh if not it won├в t run the ftp transfer script.
In my opinion, there's no need to have your code in two separate scripts, I would merge these two into a single script which also does the transfer.
pseudo-code:
if [ "file is there" && "file isn't being used" ]
then
"ftp it"
fi
>every time this script will run it sent an automated e-mail and un-necessarily it will fill the inbox with mails even if file is not sent.
This is because cron works this way. If there is any output to stdout or to stderr, it will be mailed to the user. I would redirect the output of the script to a log file. Note that you should use ">>" instead of a single ">", this way you can keep the old logs. So this is the line you should write into the crontab:
1 5 * * * /path/to/myscript 1>>/path/to/mylog 2>>/path/to/mylog
I would add to the upper script a formatting, like this, to keep the log pretty and easily readable:
echo "**************************************"
echo "starting at:"
date
echo "lets do it!"
"action, see above"
echo "finished at:
date
echo "**************************************"
..or something like this. At the moment I don't have access to an HP-UX system, that's why you only got this raw pseudo-code.
Regards,
Viktor
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-03-2010 08:43 AM
тАО10-03-2010 08:43 AM
Re: Script to write to check the file in directory if available then run the FTP transfer script.
So i just want the other script to check for file availability not to check for "reference" file's age or most recently updated.If file available then run the FTP transfer script or else if file not available then don;t run the FTP transfer script.
Thanks,
Narendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-03-2010 09:08 AM
тАО10-03-2010 09:08 AM
Re: Script to write to check the file in directory if available then run the FTP transfer script.
> So i just want the other script to check for file availability not to check for "reference" file's age or most recently updated.If file available then run the FTP transfer script or else if file not available then don;t run the FTP transfer script.
OK, then you could 'cron' this wrapper. I have incorported Jean-Luc's suggestion to verify that the file isn't inuse either. I use this technique in some of my own production scripts.
# cat ./want_to_ftp
#!/usr/bin/sh
typeset MYFILE=/var/tmp/myfile #...change accordingly...
[ -f "${MYFILE}" ] || exit 1 #...no file present...
PIDS=$(fuser ${MYFILE} 2>/dev/null) #...look for any process using file...
[ -z "${PIDS}" ] || exit 2 #...one or more users of file...
/script/FTPtransfer.ksh #...launches your FTP script
exit $?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-03-2010 10:11 PM
тАО10-03-2010 10:11 PM
Re: Script to write to check the file in directory if available then run the FTP transfer script.
Thanks...I don;t want the file to check whether it is in use as this file won;t we use by any users.
And can we simply write the logic to check whether file is avialabe in /ftpfile/outbox directory through ll |wc -l and if it gives and output 2 then the FTP transfer
script will run or else it won;t run the FTP transfer script. Or any other logic without using process id.
Thanks,
Narendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-03-2010 10:21 PM
тАО10-03-2010 10:21 PM