Partial list with ls-l in bash script run in cron but full list run from command line
I am not exactly new to linux but I don't have much knowledge of it and this seemed the best place to put this question.
First apologies for the length of this post. I'd like to clearly explain the problem. I have an unslung nslu2 (slug) on which I have a script that copies large video files to a nas and then lists the files in the source and target directories so that I can check the files are being copied across properly. The script is a simple bash script. The source directory is on a PVR attached to the slug (topfield TF5800) and does not use linux to list the files. This part works perfectly. The target directory is on a nas running linux (terastation home server with root access). I mount the nas directory as a directory on the slug and this bit works fine. I list the files in the nas directory using linux (ls and dir) and it is this part that is giving problems. When I run the script on the slug from the command line, logged on as root, it works perfectly and is able to email me a complete, formatted list of files in the target directory using either ls-l or dir-l. ls-l is better because the dir-l leads to lots of escape characters. However if the script is run from cron, as root, then the dir-l command leads to an unformatted list with lines running one into another with no end of line carriage return. The ls-l command leads to a seemingly random list of a subset of the files in the directory. Whilst the subset does appear random it is consistent from one run to the next. I have confirmed it is a subset by looking in the directory from the command line and also ftp'ing in to the nas. The video files play properly they just aren't listed properly when the script is run from cron. I have tried several ploys to get around this including using cd within the script to change to the correct directory, within the script unmounting and mounting the target directory and even creating a pause but none of this seems to work and I still get the result described above. I have read elsewhere that it is neccesary to put the full path for commands or set environment variables. The script does work partially so it seems to me that neither of these can be the solution. As I said at the start, I'm not exactly new to linux but I don't know much and I have no further ideas remaining, can anyone offer any help? Sorry for the long post. Red |
Could you post the output of 'aliases' ?
|
Sorry for my ignorance but what do you mean by 'aliases'?
Red |
Type the word 'aliases' in a terminal and press enter.
|
Thanks. In response to aliases I get the following response
aliases: No such file or directory Red |
[doh!] .. sorry, that was my fault, the command is 'alias'
|
Thanks. I typed 'alias' and it did nothing, just skipped to a new command prompt. I am logged in as root.
Red |
In your cron script... specify the absolute path of ls... such as:
/bin/ls -l Then, on your command line, do the same thing. /bin/ls -l This is a workaround, that will skip any aliases or differing versions of ls. |
Thanks for the tip to try the full path. I modified the script and let it run as a cron job. Unfortunately it did not fix the problem. I got the same partial list as before.
Is there anything else I should try? Red |
Quote:
1) Output of the command on command line 2) Outpuf of the command in the script 3) Output of 'set' 4) Output of 'whereis ls' and 'which ls' Hopefully with these, we can figure out what in the world is going on. |
Apologies for the delay responding. My attention has been taken elsewhere over the holiday.
The output you asked for is as follows. Unfortunately two of the commands were not recognised by my slug. Thank you very much for your help with all this. Red Quote:
Red |
Would be nice to find out why this is happening.
Meanwhile it might be worth trying ls -ld * or ls -1 (if you only want the file names). Alternatively the dir -l output is parseable ... |
Thanks for the comments. I will try the ls -ld * to see if that helps. I won't use ls -1 as I do want the file sizes to check the copy across when ok.
Also I agree the dir output can be made readable but here what I don't understand is why it is laid out neatly when I run the script (as root) from the command line yet when run from cron the whole output is dumped into a single line. I did think some character was being suppressed for this to happen but I cannot understand why this part is different in the different situations. Anyway thank you for your help. I will try ls -ld * and report back here. Thank you. Red |
Quote:
|
Thanks for all the input.
I tried ls -ld * and the output was just as before (thanks though) Red |
All times are GMT -5. The time now is 08:03 PM. |