Sponsored Content
Top Forums Shell Programming and Scripting Works from bash prompt, but not from script! Post 302165895 by siegfried on Saturday 9th of February 2008 05:53:01 PM
Old 02-09-2008
Where do those ^M keep coming from?

I just when back to the script file and noticed that someone has inserted ^M at the end of each line! Hmmm... This could explain some of those error messages. While this is still a bash question, it might be a windows problem. Is there a way to make bash tolerate the ^M?

Here is the entire file:
Code:
#!/usr/bin/bash
#
# Begin commands to execute this file using bash with bash
# chmod +x backup.bash
# ./backup.bash
# End commands to execute this file using bash with bash
#
# $Log$
#
set -xv
cp /cygdrive/c/.emacs .
cp /cygdrive/c/.viper .
ls

#pushd Documents\ and\ Settings/Administrator
#unison "/cygdrive/c/Documents and Settings/Administrator/.m2" .m2 
#unison "/cygdrive/c/Documents and Settings/Administrator/.maven" .maven 
#unison "/cygdrive/c/Documents and Settings/Administrator/.middlegen" .middlegen 
#unison "/cygdrive/c/Documents and Settings/Administrator/.mysqlcc" .mysqlcc 
#unison "/cygdrive/c/Documents and Settings/Administrator/.squirrel-sql" .squirrel-sql 
#unison "/cygdrive/c/Documents and Settings/Administrator/Application Data" Application Data 
#unison "/cygdrive/c/Documents and Settings/Administrator/Bluetooth Software" Bluetooth Software 
#unison "/cygdrive/c/Documents and Settings/Administrator/Contacts" Contacts 
#unison "/cygdrive/c/Documents and Settings/Administrator/Desktop" Desktop 
#unison "/cygdrive/c/Documents and Settings/Administrator/Favorites" Favorites 
#unison "/cygdrive/c/Documents and Settings/Administrator/Incomplete" Incomplete 
#unison "/cygdrive/c/Documents and Settings/Administrator/Local Settings" Local Settings 
#unison "/cygdrive/c/Documents and Settings/Administrator/My Documents" My Documents 
#unison "/cygdrive/c/Documents and Settings/Administrator/NTUSER.DAT" NTUSER.DAT 
#unison "/cygdrive/c/Documents and Settings/Administrator/NetHood" NetHood 
#unison "/cygdrive/c/Documents and Settings/Administrator/PUTTY.RND" PUTTY.RND 
#unison "/cygdrive/c/Documents and Settings/Administrator/java6" java6 
#unison "/cygdrive/c/Documents and Settings/Administrator/runtime-EclipseApplication" runtime-EclipseApplication 
#unison "/cygdrive/c/Documents and Settings/Administrator/ssh" ssh 
#unison "/cygdrive/c/Documents and Settings/Administrator/workspace" workspace 
#popd

unison "/cygdrive/c/busines" "busines" 
#unison "/cygdrive/c/C++ Labs" "C++ Labs"
#unison "/cygdrive/c/CVS" "CVS" 
#unison "/cygdrive/c/CVS_2006" "CVS_2006" 
#unison "/cygdrive/c/CVS_Books" "CVS_Books" 
#unison "/cygdrive/c/CVS_Bugzilla_2_14_5" "CVS_Bugzilla_2_14_5" 
#unison "/cygdrive/c/CVS_C++" "CVS_C++" 
#unison "/cygdrive/c/CVS_Config" "CVS_Config" 
#unison "/cygdrive/c/CVS_Diary" "CVS_Diary" 
#unison "/cygdrive/c/CVS_GMM" "CVS_GMM" 
#unison "/cygdrive/c/CVS_LectureNotes" "CVS_LectureNotes" 
#unison "/cygdrive/c/CVS_Loki" "CVS_Loki" 
#unison "/cygdrive/c/CVS_OOP" "CVS_OOP" 
#unison "/cygdrive/c/CVS_OpenSource" "CVS_OpenSource" 
#unison "/cygdrive/c/CVS_Pillar" "CVS_Pillar" 
#unison "/cygdrive/c/CVS_Pillar_XSLT" "CVS_Pillar_XSLT" 
#unison "/cygdrive/c/CVS_ProSpring" "CVS_ProSpring" 
#unison "/cygdrive/c/CVS_Tomcat" "CVS_Tomcat" 
#unison "/cygdrive/c/CVS_WinOOP" "CVS_WinOOP" 
#unison "/cygdrive/c/CVS_YahooFinanceBot" "CVS_YahooFinanceBot" 
#unison "/cygdrive/c/CVSBusiness" "CVSBusiness" 
#unison "/cygdrive/c/CVSNT" "CVSNT" 
#unison "/cygdrive/c/CVSROOT" "CVSROOT" 
#unison "/cygdrive/c/dev" "dev" 
#unison "/cygdrive/c/DiskSpace" "DiskSpace" 
#unison "/cygdrive/c/Documents and Settings" "Documents and Settings" 
#unison "/cygdrive/c/emacs" "emacs" 
#unison "/cygdrive/c/inetpub" "inetpub" 
#unison "/cygdrive/c/OOP" "OOP" 
#unison "/cygdrive/c/WinOOP" "WinOOP"

Here are all the error messages again after I ran it again after remove the ^M at the end of each line.
Quote:
bash-3.2$ set -xv
bash-3.2$ ./backup.bash
./backup.bash
+ ./backup.bash
: invalid option
set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
./backup.bash: line 13: $'ls\r': command not found
./backup.bash: line 14: $'\r': command not found
./backup.bash: line 37: $'\r': command not found
Error: Ill-formed name of file in UNISON directory: /cygdrive/c/busines
bash-3.2$
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

substring command works but only in BASH shell

I am having trouble running a .sh file. The code 'x=${file_name:0:$z-11}' is giving me a bad substitution error. However when I run in BASH it works. Thing is when this goes to production the .sh will not be running in BASH. Is there a way to substring a string not in BASH or a way to invoke... (2 Replies)
Discussion started by: edwardtk11
2 Replies

2. Shell Programming and Scripting

Script works with bash 3.0 but not 3.2.

Hello, So my knowledge of bash scripting is not that great and I have been trying to solve this problem on my own for awhile to no avail. Here's the error I get when running it with an OS that uses bash 3.2.x: testagain.sh: line 10: *-1: syntax error: operand expected (error token is... (2 Replies)
Discussion started by: forkandspoon
2 Replies

3. OS X (Apple)

Bash script prompt for sudo password?

I'm making a script that will be a double clickable .command file and I need it to prompt for the users admin password. So far I have: if ]; then sudo -p "Please enter your admin password: " date 2>/dev/null 1>&2 if ; then echo "You entered an invalid password... (2 Replies)
Discussion started by: PatGmac
2 Replies

4. UNIX for Dummies Questions & Answers

FTP that works correctly in command prompt and shows issue in UNIX server

Hi All, FTP ports opens with the given user name and password and allows to download file through COMMAND PROMPT. Code as below: H:\>ftp ftpxxxxx Connected to entvc2ft07-pub.xxxxx.com. 220 Microsoft FTP Service User (entvc2ft07-pub.xxxxx.com:(none)): userxxxxx 331 User name okay, need... (1 Reply)
Discussion started by: vijayalakshmi.r
1 Replies

5. UNIX for Dummies Questions & Answers

Bash script dont works when executed as cronjob

Hello, i have cronjob: crontab -l * * * * * pkill -f domexpcheck;sh /root/dom/domexpcheck.sh it runs: /var/log/cron Mar 25 12:11:01 vps crond: (root) CMD (pkill -f domexpcheck;sh /root/dom/domexpcheck.sh) but somehow script dont run properly via cronjob. But when i execute cronjob... (7 Replies)
Discussion started by: postcd
7 Replies

6. Shell Programming and Scripting

Calling bash script works when called manually but not via Cron?

Hi, I've got a Bash backup script I'm trying to run on a directory via a cron job nightly. If I ssh in and run the script manually it works flawlessly. If I set up the cron to run evertything is totally messed up I don't even know where to begin. Basically the path structure is ... (6 Replies)
Discussion started by: wyclef
6 Replies

7. Shell Programming and Scripting

Script in bash that works only some of the time

I ran this script yesterday (in the background) /usr/bin/nohup myfilelocation/myscriptname.sh & the script worked perfectly. i ran it today (also in the background) and just sat there. So i killed it and ran it normally and it worked perfectly. Anyone suggest why it just sat there and... (8 Replies)
Discussion started by: twinion
8 Replies

8. UNIX for Dummies Questions & Answers

Shell script not working but command works in command prompt

Hi everyone I have a problem with my script If I try directly this command /usr/bin/nice -n 19 mysqldump -u root --password="******" wiki_schneider -c | nice -n 19 gzip -9 > /point_de_montage/$(date '+%Y%m%d')-wiki-db.sql.gz It works But if I simply add this command in a script and... (8 Replies)
Discussion started by: picemma
8 Replies

9. Shell Programming and Scripting

Linux/bash Script only working if executed from shell prompt

Hi, maybe I'm asking a VERY dumb question, but would anybody out there tell me, why this f****** script won't work if executed as a cronjob, but works fine if executed from a shell prompt? #! /bin/bash set PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin date >>... (3 Replies)
Discussion started by: beislhur
3 Replies

10. UNIX for Beginners Questions & Answers

Command works interactively but not in bash script

The below command works in the terminal interactively but not as part of a bash script. I though maybe I needed to escape the "$dir" so it isn't interpreted literally, but that's not it. Thank you :). interactively in terminal dir=/path/to new=$(ls "$dir"/*.csv -tr | tail -n 1) && echo... (6 Replies)
Discussion started by: cmccabe
6 Replies
All times are GMT -4. The time now is 02:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy