[SOLVED] Partial list with ls-l in bash script run in cron but full list run from command line
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
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.
Welcome to Unslung V2.3R63-uNSLUng-6.8-beta
---------- NOTE: THIS SYSTEM IS CURRENTLY UNSLUNG ----------
BusyBox v0.60.4 (2005.03.22-06:52+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.
. : alias break builtin cd chdir continue eval exec exit export
false fc hash help jobs let local pwd read readonly return set
setvar shift times trap true type ulimit umask unalias unset
-rwx------ 1 root root 2676783104 Dec 10 11:03 Alvin and the Chipmunks_101128.rec
-rwx------ 1 root root 2489950208 Dec 14 10:06 Any Human Heart_101121.rec
-rwx------ 1 root root 2074701824 Dec 14 11:01 Any Human Heart_101128.rec
-rwx------ 1 root root 2171054080 Dec 14 11:55 Any Human Heart_101205.rec
-rwx------ 1 root root 2069696512 Dec 14 12:45 Any Human Heart_101212.rec
-rwx------ 1 root root 1868810240 Dec 10 09:49 Babe_101114.rec
-rwx------ 1 root root 3502274560 Dec 1 11:29 Close Encounters of the Third Kind_101120.rec
-rwx------ 1 root root 2403512320 Dec 1 12:25 Dr No_101123.rec
-rwx------ 1 root root 2435854336 Dec 9 10:00 From Russia with Love_101202.rec
-rwx------ 1 root root 3909341184 Dec 9 11:29 Goldfinger_101127.rec
-rwx------ 1 root root 2066905088 Dec 13 10:59 Ladies in Lavender_101204.rec
-rwx------ 1 root root 2687948800 Dec 13 10:08 Mrs Doubtfire_101204.rec
-rwx------ 1 root root 4439422976 Dec 11 12:34 North by Northwest_101122.rec
-rwx------ 1 root root 2137460736 Dec 19 10:04 Singin' in the Rain_101125.rec
-rwx------ 1 root root 3166148608 Dec 11 14:02 Sweeney Todd The Demon Barber of Fleet_101127.rec
-rwx------ 1 root root 2301673472 Dec 12 13:12 Tea with Mussolini_101204.rec
-rwx------ 1 root root 3492745216 Dec 11 10:40 The Mission_101116.rec
-rwx------ 1 root root 3814914048 Dec 13 12:26 The Perfect Storm_101208.rec
-rwx------ 1 root root 2629425152 Dec 1 10:06 The Spiderwick Chronicles_101114.rec
-rwx------ 1 root root 1730394112 Dec 9 12:09 The Witches_101128.rec
-rwx------ 1 root root 3728764928 Dec 12 12:17 Thirteen Days_101124.rec
-rwx------ 1 root root 3766112256 Dec 12 10:38 Those Magnificent Men in Their Flying M_101203.rec
drwx------ 1 root root 4096 Aug 12 00:23 avi
drwx------ 1 root root 4096 Jun 21 2009 mpg
-rwxr-xr-x 1 root root 2074701824 Dec 14 11:01 Any Human Heart_101128.rec
-rwxr-xr-x 1 root root 2069696512 Dec 14 12:45 Any Human Heart_101212.rec
-rwxr-xr-x 1 root root 1868810240 Dec 10 09:49 Babe_101114.rec
-rwxr-xr-x 1 root root 2066905088 Dec 13 10:59 Ladies in Lavender_101204.rec
-rwxr-xr-x 1 root root 2137460736 Dec 19 10:04 Singin' in the Rain_101125.rec
-rwxr-xr-x 1 root root 1730394112 Dec 9 12:09 The Witches_101128.rec
drwxr-xr-x 1 root root 4096 Aug 12 00:23 avi
drwxr-xr-x 1 root root 4096 Jun 21 2009 mpg
I hope this is what you were after. As before thank you very much with your help trying to sort this out
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.