LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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.

Notices

Reply
 
Search this Thread
Old 12-21-2010, 03:43 PM   #1
redgshost
LQ Newbie
 
Registered: Dec 2010
Posts: 15

Rep: Reputation: 0
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
 
Old 12-21-2010, 05:17 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,758

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Could you post the output of 'aliases' ?
 
Old 12-22-2010, 03:59 PM   #3
redgshost
LQ Newbie
 
Registered: Dec 2010
Posts: 15

Original Poster
Rep: Reputation: 0
Sorry for my ignorance but what do you mean by 'aliases'?

Red
 
Old 12-22-2010, 07:24 PM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,758

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Type the word 'aliases' in a terminal and press enter.
 
Old 12-22-2010, 07:27 PM   #5
redgshost
LQ Newbie
 
Registered: Dec 2010
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks. In response to aliases I get the following response

aliases: No such file or directory

Red

Last edited by redgshost; 12-22-2010 at 07:29 PM.
 
Old 12-22-2010, 07:30 PM   #6
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,758

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
[doh!] .. sorry, that was my fault, the command is 'alias'
 
Old 12-23-2010, 02:25 PM   #7
redgshost
LQ Newbie
 
Registered: Dec 2010
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks. I typed 'alias' and it did nothing, just skipped to a new command prompt. I am logged in as root.

Red
 
Old 12-23-2010, 02:29 PM   #8
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,369
Blog Entries: 1

Rep: Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088
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.
 
Old 12-23-2010, 08:12 PM   #9
redgshost
LQ Newbie
 
Registered: Dec 2010
Posts: 15

Original Poster
Rep: Reputation: 0
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
 
Old 12-27-2010, 01:40 PM   #10
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,369
Blog Entries: 1

Rep: Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088Reputation: 1088
Quote:
Originally Posted by redgshost View Post
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
Could you provide me a few things as root? Obviously you can scrub any output that you do not wish to share.

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.
 
Old 12-30-2010, 02:50 AM   #11
redgshost
LQ Newbie
 
Registered: Dec 2010
Posts: 15

Original Poster
Rep: Reputation: 0
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:
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.

# help

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
wait

# set
SSH_CLIENT=xx
USER='root'
MAIL='/var/mail/root'
HOME='/root'
SSH_TTY='/dev/ttyp0'
PS1='# '
OPTIND='1'
PS2='> '
LOGNAME='root'
TERM='xterm'
PPID='953'
PATH='/opt/sbin:/opt/bin:/usr/sbin:/usr/bin:/sbin:/bin'
SHELL='/bin/sh'
IFS='
'
PWD= xx
SSH_CONNECTION= xx


# whereis ls
whereis: No such file or directory


# which ls
which: No such file or directory


Output of script run from command line

Using dir-l

total 60120998
-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


Using ls-l

total 60120998
-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



Output of script run from cron

Using dir-l

total 60120998
-rwxr-xr-x 1 root root 2676783104 Dec 10 11:03 Alvin\ and\ the\ Chipmunks_101128.rec -rwxr-xr-x 1 root root 2489950208 Dec 14 10:06 Any\ Human\ Heart_101121.rec -rwxr-xr-x 1 root root 2074701824 Dec 14 11:01 Any\ Human\ Heart_101128.rec -rwxr-xr-x 1 root root 2171054080 Dec 14 11:55 Any\ Human\ Heart_101205.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 3502274560 Dec 1 11:29 Close\ Encounters\ of\ the\ Third\ Kind_101120.rec -rwxr-xr-x 1 root root 2403512320 Dec 1 12:25 Dr\ No_101123.rec -rwxr-xr-x 1 root root 2435854336 Dec 9 10:00 From\ Russia\ with\ Love_101202.rec -rwxr-xr-x 1 root root 3909341184 Dec 9 11:29 Goldfinger_101127.rec -rwxr-xr-x 1 root root 2066905088 Dec 13 10:59 Ladies\ in\ Lavender_101204.rec -rwxr-xr-x 1 root root 2687948800 Dec 13 10:08 Mrs\ Doubtfire_101204.rec -rwxr-xr-x 1 root root 4439422976 Dec 11 12:34 North\ by\ Northwest_101122.rec -rwxr-xr-x 1 root root 2137460736 Dec 19 10:04 Singin'\ in\ the\ Rain_101125.rec -rwxr-xr-x 1 root root 3166148608 Dec 11 14:02 Sweeney\ Todd\ The\ Demon\ Barber\ of\ Fleet_101127.rec -rwxr-xr-x 1 root root 2301673472 Dec 12 13:12 Tea\ with\ Mussolini_101204.rec -rwxr-xr-x 1 root root 3492745216 Dec 11 10:40 The\ Mission_101116.rec -rwxr-xr-x 1 root root 3814914048 Dec 13 12:26 The\ Perfect\ Storm_101208.rec -rwxr-xr-x 1 root root 2629425152 Dec 1 10:06 The\ Spiderwick\ Chronicles_101114.rec -rwxr-xr-x 1 root root 1730394112 Dec 9 12:09 The\ Witches_101128.rec -rwxr-xr-x 1 root root 3728764928 Dec 12 12:17 Thirteen\ Days_101124.rec -rwxr-xr-x 1 root root 3766112256 Dec 12 10:38 Those\ Magnificent\ Men\ in\ Their\ Flying\ M_101203.rec
drwxr-xr-x 1 root root 4096 Aug 12 00:23 avi
drwxr-xr-x 1 root root 4096 Jun 21 2009 mpg


Using ls-l

-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

Red
 
Old 12-30-2010, 04:13 AM   #12
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,557
Blog Entries: 28

Rep: Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178
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 ...
 
1 members found this post helpful.
Old 12-30-2010, 04:24 PM   #13
redgshost
LQ Newbie
 
Registered: Dec 2010
Posts: 15

Original Poster
Rep: Reputation: 0
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
 
Old 12-30-2010, 10:10 PM   #14
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,557
Blog Entries: 28

Rep: Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178
Quote:
Originally Posted by redgshost View Post
but I cannot understand why this part is different in the different situations.
It may be that dir is detecting what its stdout is going to with something like the isatty() system call.
 
1 members found this post helpful.
Old 12-31-2010, 02:52 PM   #15
redgshost
LQ Newbie
 
Registered: Dec 2010
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks for all the input.

I tried ls -ld * and the output was just as before (thanks though)

Red
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'E:Malformed line 54 in source list /etc/apt/sources.list (dist parse), E:The list of vsssuccess@gmail.com Linux - Desktop 1 11-17-2010 09:17 AM
Bash script run via cron not executing MYSQL command mackstar Linux - Server 4 04-23-2009 06:01 AM
Bash script can't handle errors when run by cron rosv Programming 4 01-08-2009 08:50 PM
Run bash commands script as cron anjanesh Linux - General 4 04-03-2007 07:25 AM
Script to Run the Same Commands on a List of Files Chryzmo Programming 1 10-03-2004 09:34 AM


All times are GMT -5. The time now is 02:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration