Shell script not working but command works in command prompt


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shell script not working but command works in command prompt
# 1  
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
Code:
/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 launch it, It don't works
This is my script

Code:
#!/bin/sh
#Database backup
/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

here is the error I have
Image

Thank you!
# 2  
The unreadabilty of the error messages indicates that there are DOS line terminators (0x0D, \r, <CR>) in the script. What editor did you use when creating it? You better use *nix editors.
These 2 Users Gave Thanks to RudiC For This Post:
# 3  
I edit this scrip with notepad++ on windows, the script is in a shared folder betwin my windows and my Debian VM
Do you belive if I edit my script via nano on my Debian VM it will works?

Thank you
# 4  
Hello picemma,

Welcome to forums, you could try following.
I- Please check about carriage return characters(control M) ones.
By following command.
Code:
cat -v Input_file

II- If you see control M characters by above command then you could try following to remove them.
Code:
tr -d '\r' < Input_file > New_Input_file

Hope this helps.

Thanks,
R. Singh
# 5  
Quote:
Originally Posted by picemma
I edit this scrip with notepad++ on windows, the script is in a shared folder betwin my windows and my Debian VM
Do you belive if I edit my script via nano on my Debian VM it will works?

Thank you
Probability is high. Why don't you give it a try?
Other measures would include modifying your script in a way RavinderSingh13 showed.
# 6  
I must be missing something.
I can't see any ^M characters after copying and pasting the script into a terminal and hexdumping the result...
Code:
Last login: Tue Feb  2 09:33:32 on ttys000
AMIGA:barrywalker~> echo '#!/bin/sh
> #Database backup
> /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' | hexdump -C
00000000  23 21 2f 62 69 6e 2f 73  68 0a 23 44 61 74 61 62  |#!/bin/sh.#Datab|
00000010  61 73 65 20 62 61 63 6b  75 70 0a 2f 75 73 72 2f  |ase backup./usr/|
00000020  62 69 6e 2f 6e 69 63 65  20 2d 6e 20 31 39 20 6d  |bin/nice -n 19 m|
00000030  79 73 71 6c 64 75 6d 70  20 2d 75 20 72 6f 6f 74  |ysqldump -u root|
00000040  20 2d 2d 70 61 73 73 77  6f 72 64 3d 22 2a 2a 2a  | --password="***|
00000050  2a 2a 2a 2a 22 20 77 69  6b 69 5f 73 63 68 6e 65  |****" wiki_schne|
00000060  69 64 65 72 20 2d 63 20  7c 20 6e 69 63 65 20 2d  |ider -c | nice -|
00000070  6e 20 31 39 20 67 7a 69  70 20 2d 39 20 3e 20 2f  |n 19 gzip -9 > /|
00000080  70 6f 69 6e 74 5f 64 65  5f 6d 6f 6e 74 61 67 65  |point_de_montage|
00000090  2f 24 28 64 61 74 65 20  2b 25 59 25 6d 25 64 29  |/$(date +%Y%m%d)|
000000a0  2d 77 69 6b 69 2d 64 62  2e 73 71 6c 2e 67 7a 0a  |-wiki-db.sql.gz.|
000000b0
AMIGA:barrywalker~> _

# 7  
Could have been lost when copy/pasting the script. Compare above error message to this:
Code:
cat file1 | gzip -9 > /point_de_montage/$(date '+%Y%m%d')-wiki-db.sql.gz
bash: /point_de_montage/$(date '+%Y%m%d')-wiki-db.sql.gz: No such file or directory

If you now imagine a <CR> after the ".gz", you'll have exactly the line posted.
This User Gave Thanks to RudiC For This Post:
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #725
Difficulty: Medium
Barbara Liskov developed the Liskov substitution principle, which guarantees semantic interoperability of data types in a hierarchy.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string works on command-line but fails when run from shell script

I wish to replace "\\n" with a single white space. The below does the job on command-line: $ echo '/fin/app/scripts\\n/fin/app/01/sql' | sed -e 's#\\\\n# #g'; /fin/app/scripts /fin/app/01/sql However, when i have the same code to a shell script it is not able to get me the same output:... (8 Replies)
Discussion started by: mohtashims
8 Replies

2. Shell Programming and Scripting

sed command not working inside ksh script but works fine outside

Hi, I am a bit confused ,why would a sed command work fine outside of ksh script but not inside. e.g I want to replace all the characters which end with a value and have space at end of it. so my command for it is : sed -i "s/$SEPARATOR /$SEPARATOR/g" file_name This is working fine in... (8 Replies)
Discussion started by: vital_parsley
8 Replies

3. Shell Programming and Scripting

perl: Command works in terminal, but not in shell script

Hi, the following command works in the terminal no problem. samtools view -h rawlib.bam | perl -ne '{ @line = split( /\s+/ ); $match = 0; while( $line =~ /(\d+)M/g ) { $match = $match + $1 } if( $match >= 80 || $_ =~ /^\@/ ) { print $_ } }' | java -Xmx12G -jar... (8 Replies)
Discussion started by: jdilts
8 Replies

4. Shell Programming and Scripting

SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes CC=`which gcc` CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Discussion started by: oly_r
8 Replies

5. Shell Programming and Scripting

Use Unix shell script to open Windows command prompt (cmd)

Hello, I work on Windows and I use Putty to access a remote UNIX server. I am trying to build a shell script that will have as main task to open the Windows command prompt (cmd) and run some Windows commands thereafter. The commands are actually file transfer commands that will download a file... (14 Replies)
Discussion started by: rookie2785
14 Replies

6. 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

7. Shell Programming and Scripting

CD command not working in shell script

Hello All, I have tried many permutaion combinations in my shell script but cd command is not working in shell script. Can any one help me out in this. Below is my script. ############ #!/bin/sh set -x on BASE_DIR=/etc/init.d export BASE_DIR cd $BASE_DIR ############# but its... (8 Replies)
Discussion started by: ajaincv
8 Replies

8. Shell Programming and Scripting

help with shell script: cp command not working, but mv command works...

Hello. I would like to ask your help regarding the cp command. We are using a cp command to create a back-up copy of our file but to no avail. It's just not working. We already checked the file and directory permissions and all seems correct. We have a script (ftp.script) which calls on... (1 Reply)
Discussion started by: udelalv
1 Replies

9. Shell Programming and Scripting

how the typeset command works in shell script

typeset -l section section=${2:-.} what does these 2 lines meaning? (1 Reply)
Discussion started by: venkatababu
1 Replies

10. UNIX for Dummies Questions & Answers

running command prompt executable file in shell script

hi i have file extentioned with test.vbs. i am able to run this file n execute through command promt but i dont know how to run in shell script example: file name is test.vbs which contains strSoundFile = "C:\windows\Media\Notify.wav" Set objShell = CreateObject("Wscript.Shell") strCommand... (5 Replies)
Discussion started by: atl@mav
5 Replies

Featured Tech Videos