LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cron script - No such file or directory (http://www.linuxquestions.org/questions/linux-newbie-8/cron-script-no-such-file-or-directory-495838/)

mokelly1 10-26-2006 02:37 PM

cron script - No such file or directory
 
It is in the man pages and in all the how to's but as a newbie (for only 3 years) I cannot seem to figure it out. I have 3 Suse 10 servers running cron jobs without a hitch although it was like pulling teeth to get them to work. It took so long to get these working that I have gone stare crazy and cannot see the problem here.

I want to run the following cron job on the 4th server named BTI.sh.


#!/bin/sh
/usr/bin/rsync -rutv --modify-window=1 /srv/www/htdocs /mnt/SuseBackup/BTI-Intranet/Scripts;
/usr/bin/mysqlhotcopy Intranet /root/Backup/Data --user=root --password=mypassword --allowold;
/usr/bin/rsync -rutv --modify-window=1 /root/Backup/Data/Intranet /mnt/SuseBackup/BTI-Intranet/Data;

Here is a strange observation. Without semicolons in the above script I get:


bti-intranet:/etc/cronsOther # sh BTI.sh
building file list ... done
rsync: mkdir "/mnt/SuseBackup/BTI-Intranet/Scripts\015" failed: No such file or directory (2)
rsync error: error in file IO (code 11) at main.c(422)
rsync: connection unexpectedly closed (8 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(434)
Unknown option: allowold
Invalid option
/usr/bin/mysqlhotcopy Ver 1.22

Usage: /usr/bin/mysqlhotcopy db_name[./table_regex/] [new_db_name | directory]

-?, --help display this helpscreen and exit
-u, --user=# user for database login if not current user
-p, --password=# password to use when connecting to server (if not set
in my.cnf, which is recommended)
-h, --host=# Hostname for local server when connecting over TCP/IP
-P, --port=# port to use when connecting to local server with TCP/IP
-S, --socket=# socket to use when connecting to local server

--allowold don't abort if target dir already exists (rename it _old)
--addtodest don't rename target dir if it exists, just add files to it
--keepold don't delete previous (now renamed) target when done
--noindices don't include full index files in copy
--method=# method for copy (only "cp" currently supported)

-q, --quiet be silent except for errors
--debug enable debug
-n, --dryrun report actions without doing them

--regexp=# copy all databases with names matching regexp
--suffix=# suffix for names of copied databases
--checkpoint=# insert checkpoint entry into specified db.table
--flushlog flush logs once all tables are locked
--resetmaster reset the binlog once all tables are locked
--resetslave reset the master.info once all tables are locked
--tmpdir=# temporary directory (instead of /tmp)
--record_log_pos=# record slave and master status in specified db.table
--chroot=# base directory of chroot jail in which mysqld operates

Try 'perldoc /usr/bin/mysqlhotcopy' for more complete documentation
building file list ... done
rsync: mkdir "/mnt/SuseBackup/BTI-Intranet/Data\015" failed: No such file or directory (2)
rsync error: error in file IO (code 11) at main.c(422)
rsync: connection unexpectedly closed (8 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(434)


With the semicolons I get a 'command not found' for each semicolon but it works:

bti-intranet:/etc/cronsOther # sh BTI.sh
building file list ... done

sent 19845 bytes received 20 bytes 39730.00 bytes/sec
total size is 35819869 speedup is 1803.16
: command not found
Existing hotcopy directory renamed to '/root/Backup/Data/Intranet_old'
Locked 27 tables in 0 seconds.
Flushed tables (`Intranet`.`ActionLinks`, `Intranet`.`Actions`, `Intranet`.`ConsignmentPurchaseOrder`, `Intranet`.`ControlPoints`, `Intranet`.`EMailQue`, `Intranet`.`Employee`, `Intranet`.`FeederAudit`, `Intranet`.`Forecast`, `Intranet`.`ForecastMonth`, `Intranet`.`Job`, `Intranet`.`Labor`, `Intranet`.`Layout`, `Intranet`.`PartCategories`, `Intranet`.`PartsPrices`, `Intranet`.`People`, `Intranet`.`ProcessThread`, `Intranet`.`Processes`, `Intranet`.`QualityAlertStatusCodes`, `Intranet`.`QualityAlerts`, `Intranet`.`RackParts`, `Intranet`.`SMTCycleTimes`, `Intranet`.`SMTPartNotes`, `Intranet`.`SubstituteParts`, `Intranet`.`TimeAbsentTardy`, `Intranet`.`TimeCards`, `Intranet`.`TopLevelRevisions`, `Intranet`.`Triggers`) in 0 seconds.
Copying 82 files...
Copying indices for 0 files...
Unlocked tables.
mysqlhotcopy copied 27 tables (82 files) in 1 second (1 seconds overall).
: command not found
building file list ... done
Intranet/
Intranet/Actions.MYD
Intranet/Actions.MYI
Intranet/Labor.MYD
Intranet/Labor.MYI
Intranet/TimeAbsentTardy.MYD
Intranet/TimeAbsentTardy.MYI

sent 26658597 bytes received 158 bytes 5924167.78 bytes/sec
total size is 34603952 speedup is 1.30
: command not found


Here is my crontab for root:

# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/root/BTICrontab installed on Thu Oct 26 13:45:44 2006)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
MAILTO=mkelly@bottomstechnology.com
SHELL=/bin/sh
PATH=/bin:/usr/bin:
47 * * * * /etc/cronsOther/BTI.sh

I get the following email:

/bin/sh: /etc/cronsOther/BTI.sh
: No such file or directory

Here is the directory:

bti-intranet:/etc/cronsOther # dir
total 20
drwxr-xr-x 2 root root 120 Oct 26 13:45 .
drwxr-xr-x 94 root root 8320 Oct 26 11:23 ..
-rwxrwxr-x 1 root root 301 Oct 26 13:45 BTI.sh
-rwxrwxr-x 1 root root 301 Oct 26 13:45 BTI.sh~
-rwxr-xr-x 1 root root 196 Oct 25 15:15 test
bti-intranet:/etc/cronsOther #

I must be overlooking something simple. Thank you for your help!

gilead 10-26-2006 05:29 PM

If I read that right, without the semi-colons the script is being treated as one long (mangled) command. Did you create the script under Windows instead of Linux? The line endings might be DOS style instead of UNIX.

You could try the following:
Code:

fromdos < /etc/cronsOther/BTI.sh > /etc/cronsOther/BTI-new.sh
If you don't have fromdos, you may have dos2unix. I think the syntax is:
Code:

dos2unix /etc/cronsOther/BTI.sh

matthewg42 10-26-2006 07:07 PM

What filesystem type do you store this script on?

mokelly1 10-27-2006 10:13 AM

Created with Gedit on Suse 10
 
I created the script using Suse 10 - Gedit and stored it on the hard drive of the Linux box. The hard drive was partitioned by the Suse 10 install and I chose the default settings. Nothing unusual here. However, I did email the script from the first Linux machine to a Windows machine opened and saved it to the latest Linux drive. The 'dos2unix /etc/cronsOther/BTI.sh' fixed the bad command issue when running BTI.sh from the command line.

However, I still get:


/bin/sh: /etc/cronsOther/BTI.sh
: No such file or directory

from cron executing it?

mokelly1 10-27-2006 10:33 AM

Well gilead, your geniusity is validated once again. I ran the dos2unix command on BTI.sh, those pesky dos cr and lf's went away and the script was found and executed properly by cron.

Many thanks!

gilead 10-27-2006 02:31 PM

That's good news - I mean the bit about it working ;)


All times are GMT -5. The time now is 09:53 PM.