fuser exit code different when script is run from cron
Hi,
I am writing a bash script (running on Centos 5.4) to process video (.MTS) files which may have appeared in a certain directory. The files will be dragged and dropped there from a Windows box using Samba, and the script is to check periodically (i.e. run from cron) whether any new .MTS files have arrived and process them if so.
However, due to the size of the files and their method of arrival, it is possible that when the script starts to run, the files may still be in the process of being copied in and will thus be incomplete. In such circumstances the script is to ignore them and exit. I have been using fuser for this purpose, as per the following code snippet:
If I manually copy some big files into the designted directory and then kick off the script (as root) from the command line, the test lines above show that the fuser exit code is 0, and the output from the script is as follows:
Once the files have finished copying, if I run the script from the command line again, the fuser exit code is 1, and I get the following output from the script:
This is exactly what I want the script to do, and it appears to be working perfectly. However the problem starts when I try to automate the process by calling the script from cron. The following is my entry in (root's) crontab:
If I again copy some large files into the directory just as the cron entry is about to run, I find that the script still proceeds to process the files, despite them being in use (I sent the output to a log file). This time the exit code from the fuser command is 127, and because it is not 0 the script is proceeding to process the files when it should not do.
What I don't understand is why the fuser exit code is different when the script is run from cron (also I don't know what exit code 127 means). Can anyone shed any light on this strange behaviour and help me to solve this problem please?
Thank you in advance.
---------- Post updated at 03:26 PM ---------- Previous update was at 11:40 AM ----------
I figured it out.
It turns out that the exit code 127 was not from the fuser command but from bash, telling me that it couldn't find fuser. I needed to use the full path to fuser in the script:
With that in place it works great. Hope this helps someone else who may be as confounded by it as I was!
Hi,
Not sure whether there is a fuser alternative or any better way to check for file in use or not.
I am wanting to check whether files are in use or not before removing them. Using fuser, the awk seems to be giving me 'weird' output not to mention that it is giving me 2 lines instead of... (0 Replies)
Hi All,
I have a script which checks the status of HP Smart Array & then emails me the output.
The script run fine when executed manually but I receive no output when configured in a cron job.
The script is below:
hpacucli ctrl slot=3 show config | mail -s "ARRAY STATUS-`date`"... (6 Replies)
Hi
I am checking status of sftp in Health check script, sftp command is used to connect the server with secure RSA key, which is successfully get connected most of the time but in some case if RSA key ask for password then I need to exit sftp command after few second and continue to run... (1 Reply)
Hi,
I have script in the cron which run at predefined time everyday.
If the script fails then we get the mail and a log is created.
But last night the script didnt run. If the script is even started it creates log so it seems the script never ran. It has never happened before.
Th... (5 Replies)
Good morning. I am searching for "how-to"'s for some particular questions:
1. How to write a script in HP-UX 11.
2. How to schedule a script.
3. How to "call" scripts from the original script.
4. How to su to another user from within a script.
This is the basics of what the... (15 Replies)
Hi, new to this forum and not sure if this is the right place to post. I'm new to cron jobs and scripts, and I need some help with a script to be used with a cron job. I already have a bot set up at a certain website address and need a script that the cron job will load every day that tells it to... (1 Reply)
Hello,
I have a shell script that runs every minute to process incoming files delivered externally via SFTP to a directory. Basically the script works and processes the files however I get an error when a new file is delivered into the directory.
Please see my script below. A new file is... (2 Replies)
Hi all,
I have a main script (called OracleCleanup) that runs some sql queries. that runs off a wrapper script which contains the sources for the login information and and JOB_HOME (the script is below). When I schedule this job in the cron the log says that it cannot open my list file, which... (4 Replies)