Command executes on the command line but not from script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command executes on the command line but not from script
# 1  
Old 04-10-2011
Command executes on the command line but not from script

Hello guys,

I have the following commands :

Command 1: sudo find "../bundlepool" -name "merchandising2.html" -print0 |xargs -0 -I {} cp "rebranding/merchandising2.html" {}
Command 2: find "../bundlepool" -name "merchandising2.html" -exec cp rebranding/merchandising2.html {} \;
Command 3: find ../bundlepool -name merchandising2.html -exec echo {} \;


They all execute fine from the command line, but none works from a script file (just created an sh file with one command)

The problems are as follows:
Command 1: no errors, but the expected result does not happen
Command 2: find: missing argument to `-exec'
Command 3: find: missing argument to `-exec'

I tried the following solutions with no success:
1- adding #!/bin/bash
2- double quoting some/all of the parameters
3-single quoting some/all of the parametersenv
4- escaping some of the special characters with a backslash
5- gave my file full authorizations (chmod a+rwx)
6- run the script with sh and with bash

Any idea what am I doing wrong?
Thanks in advance!

This is my env: ubuntu 10.04
SHELL=/bin/bash
TERM=xterm
XDG_SESSION_COOKIE=4d746282656dcbc99723045c4d999050-1302379429.6717-927508648
SSH_CLIENT=192.168.0.14 63899 22
SSH_TTY=/dev/pts/0
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:hl=44;37Smiliei=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01Smilier=40;3 1;01:su=37;41:sg=30;43:ca=30;41:tw=30;42Smiliew=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01 ;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2 =01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;3 1:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*. pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png =01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=0 1;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35 :*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.g l=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01; 35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36: *.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
MAIL=/var/mail/root
PWD=/var/www/cloud/belgacom
LANG=en_US.UTF-8
HOME=/root
SHLVL=2
LOGNAME=root
SSH_CONNECTION=192.168.0.14 63899 192.168.0.15 22
LESSOPEN=| /usr/bin/lesspipe %s
LESSCLOSE=/usr/bin/lesspipe %s %s
_=/usr/bin/env



aliases:

alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

---------- Post updated at 04:21 AM ---------- Previous update was at 03:26 AM ----------

Hello guys,

Actually I found it! my script file came from a windows system and the locale of the file was set to DOS( I knew it by running ":setlocal ff" in vim).

to change it to unix, just run ":setlocal ff=unix"

Ihab
# 2  
Old 04-10-2011
Hi; does your script contain the trailing semicolon (in 2 and 3)?

I like to construct my find calls with printf like so:
Code:
source=rebranding/merchandising2.html 
find . -name merchandising2.html -printf "cp $source %p\n"

Then you look at the output, and if it looks good, you execute it by piping to sh:
Code:
find . -name merchandising2.html -printf "cp $source %p\n" | sh

This makes debugging much easier.
# 3  
Old 04-10-2011
thanks!

Thanks for the info, this will definitely help next time I am trying to debug.

I have actually updated my post earlier with the solution! thanks a ton though for your help.

Quote:
Hello guys,

Actually I found it! my script file came from a windows system and the locale of the file was set to DOS( I knew it by running ":setlocal ff" in vim).

to change it to unix, just run ":setlocal ff=unix"

Ihab
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Another one line command where I'd like to determine if Ubuntu or Red Hat when running command

Hello Forum, I'm making very good progress on my report thanks to the very helpful people on this forum. I've been able to successfully create my report for my Red Hat servers. But I do have a few ubuntu servers in the mix and I'd like to capture some data from them when an ssh connection is... (8 Replies)
Discussion started by: greavette
8 Replies

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

3. UNIX for Dummies Questions & Answers

How does the command "script" executes?

Hi i was searching for the source code of the unix/linux command "script" but i could not find any where. could some one explain How can we write a program which runs at background and reading the current terminal ? (1 Reply)
Discussion started by: rakeshkumar
1 Replies

4. UNIX for Dummies Questions & Answers

Running set options from the command line and bash command

I'm reading about debugging aids in bash and have come across the set command. It says in my little book that an addition to typing set you can also use them "on the command line when running a script..." and it lists this in a small table: set -o option Command Line... (5 Replies)
Discussion started by: Straitsfan
5 Replies

5. UNIX for Advanced & Expert Users

unix command : how to insert text at the cursor location via command line?

Hi, Well my title isn't very clear I think. So to understand my goal: I have a script "test1" #!/bin/bash xvkbd -text blabla with xbindkeys, I bind F5 key in order it runs my test1 script So when I press F5, test1 runs. I'm under Emacs/Vi and I press F5 in order to have "blabla" be... (0 Replies)
Discussion started by: xib.be
0 Replies

6. Shell Programming and Scripting

perl script command line option driven script

could someone show me a sample command line option driven script? i want to see an easy way to write one and how i can execute it using command line options such as typing in read.pl -i <id> -c <cmds> -s <start> -e <end> would read out all the commands run by ID . from start time to... (7 Replies)
Discussion started by: kpddong
7 Replies

7. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

8. Shell Programming and Scripting

Is command line invocation of gnome-terminal to run more than one command possible?

Hello, I am trying to learn how to pass something more than a one-command startup for gnome-terminal. I will give an example of what I'm trying to do here: #! /bin/bash # #TODO write this for gnome and xterm USAGE=" ______________________________________________ ${0##*/} run... (0 Replies)
Discussion started by: Narnie
0 Replies

9. Shell Programming and Scripting

How to write an at command which executes a script every month on 3 rd

Hi Any one pls give me the at command which runs 3 rd of every month at 2 am. Its urgent ...Your help would be so much for me Thanks .. (3 Replies)
Discussion started by: rxg
3 Replies

10. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies
Login or Register to Ask a Question