Script test failing


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script test failing
# 1  
Old 03-21-2014
Script test failing

Testing some old script developed by different user.
Code:
#!/usr/bin/sh
case "$0" in
  */*) cmd="$0";;
  *) cmd=`which "$0"`;;
esac
dir=`dirname "$cmd"`
node="$dir/."
echo $node

below two simple tests are failing, I am not seeing any Control+M characters in the script file and I am not able to understand error from second test.

First test:
Code:
$ ./usernames.sh
-bash: ./usernames.sh: /usr/bin/ksh^M: bad interpreter: No such file or directory

Second test:
Code:
$ sh -x usernames.sh
'sernames.sh: line 2: syntax error near unexpected token `in
'sernames.sh: line 2: `case "$0" in

I appreciate any help.

Thanks in advance

Markar

Last edited by Franklin52; 03-21-2014 at 04:02 AM.. Reason: Please use code tags
# 2  
Old 03-21-2014
Hello Markar,

Please use the code tags for commands as per forum rules. Could you please let us know what is the input and expected output for your request.


Thanks,
R. Singh
# 3  
Old 03-21-2014
The error says you are using incorrect ksh path in the first line...but your script shows you are using sh

type the below command and use the first relust in the script

Code:
$ whereis sh
sh: /bin/sh /sbin/sh /usr/share/man/man1p/sh.1p.gz /usr/share/man/man1/sh.1.gz
$ cat usernames.sh
#! /bin/sh
case "$0" in
*/*) cmd="$0";;
*) cmd=`which "$0"`;;
esac
dir=`dirname "$cmd"`
node="$dir/."
echo $node
$

# 4  
Old 03-21-2014
The errors show that you have edited your shell script with an editor that replaced the UNIX <newline> line terminators with the Windows <carriage-return><newline> line terminators. Get rid of the <carriage-return> characters and you might have better luck. Unfortunately, it is also VERY clear that the errors you showed us from the shell did not come from the shell script you showed us; so there is no way to know if that is your only problem.
Code:
cp usernames.sh _usernames.sh && tr -d '\r' < _usernames.sh > usernames.sh

# 5  
Old 03-21-2014
Thanks Don

Followed your suggestion and now script is running successfully.

Thanks
Markar
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

PERL DBD make test on Linux failing

I am installing Oracle DBD to PERL 5.16.3 and during make test , I am running into this error :rm -f blib/arch/auto/DBD/Oracle/Oracle.so LD_RUN_PATH="/opt/oracle/product/11.2.0/racdb11204/lib" gcc -m32 -shared -O2 -L/usr/local/lib -fstack-protector Oracle.o dbdimp.o oci8.o -o... (3 Replies)
Discussion started by: talashil
3 Replies

2. UNIX for Dummies Questions & Answers

Crontab script failing

Hello, A crontab script is failiing everyday but when we execute manually it runs fine Below is the script scheduled: 00 23 * * * sh /db2backup/scripts/db2_hot_backup.ksh TRAVFF > /dev/null 2>&1 Error: cat TRAVFF_online_04022014_2300.log Started : Wed Apr 2 23:00:00 EDT 2014... (2 Replies)
Discussion started by: Vishal_dba
2 Replies

3. Shell Programming and Scripting

Test file script - if evaluation failing

I have a following script to evaluate if file exist in the directory and then archive it. #!/bin/bash #master directory scriptdir="/flex/sh/interfaces" #change this path only - all other paths are connected with it filedir="/flex/interfaces" #change this path only - all other paths are... (3 Replies)
Discussion started by: viallos
3 Replies

4. Shell Programming and Scripting

SCP Failing - In Script

I create a file that may contain several full path name files on a remote Linux that are to be copied. This file, called AWKOUTPUT is created from another script. It contains: X/picture1.png The script is very simple ------------------------------------------- REMOTEDIR="/var/CC/Stuff"... (4 Replies)
Discussion started by: mohrsville12
4 Replies

5. Shell Programming and Scripting

Expect script help needed- script failing if router unavailable

Hey all. Sometimes I'm tasked to change some router configs for the entire network (over 3,000 Cisco routers). Most of the time its a global config parameter so its done with a loop and an IP list as its the same configuration change for all routers. This is working OK. However, sometimes an... (3 Replies)
Discussion started by: mrkz1974
3 Replies

6. Shell Programming and Scripting

Display which test in the if/else is failing

So I have a script that monitors my drives (/dev/sda and /dev/sdb) using smartctl (smartmontools). I'm by no means an expert in scripting, so this was my attempt at creating a way to email me if one of the values in smartctl output goes above a set threshold. My question is, I'm trying to edit... (5 Replies)
Discussion started by: bound4h
5 Replies

7. Shell Programming and Scripting

Script failing on Solaris 10 and working on 8

I have a script and code is like this .. if ]; then it's compiling about @ . what's the wrong in Solaris 10 with this? Thanks (1 Reply)
Discussion started by: talashil
1 Replies

8. UNIX for Dummies Questions & Answers

failing a unix script

i am basically DWH professional. I want to write a script such that whenver the file size is greather than 0 the script fails plz help me in this (1 Reply)
Discussion started by: er_zeeshan05
1 Replies

9. Shell Programming and Scripting

IF condition failing in a SSH script

Hi, I'm ssh-in to a remote machine (ubuntu) and trying to execute a little script in there.The script looks like this: ssh user@ubuntu <<EOF cd ~/test ls -l echo "Continue counting files starting with a`s ?" read answer if then ls -l a* else exit fi EOF Now everything works... (9 Replies)
Discussion started by: rubionis
9 Replies

10. UNIX for Advanced & Expert Users

UNIX script failing ....

Hi folks, I have written down a UNIX script which actually FTP the file to other server. What is happening now , this script is not working only for 1 server , as it is working for 32 different FTP server . In this particular server , we are getting message “FTp:550 access denied”... (1 Reply)
Discussion started by: khan1978
1 Replies
Login or Register to Ask a Question