2

I would like to know what is the error in the below script

i get error as : command not foundh: line 1: , : command not foundh: line 2: its continuous

i have tried add ; but now working kindly tell me what to do ??

#!/bin/bash;
clear;
FILEREPO=http://192.168.1.2/cpplugin;

echo "-----------------------------------------------";
echo " Welcome to C-Panel Login Alert Installer";
echo "-----------------------------------------------";
    cd /var/cpanel/;
    mkdir perl5
    cd perl5/
    mkdir lib
    cd lib/
    wget $FILEREPO/LoginAlerthook.zip
    unzip LoginAlerthook.zip
    rm -r LoginAlerthook.zip
    cd /
    /usr/local/cpanel/bin/manage_hooks add module LoginAlert
    chmod 777 LoginAlert.pm
    echo " "
    echo " Login Alert Script Hooked With C Panel Finished"
    echo " "
Nokia808Freak
  • 903
  • 9
  • 33

5 Answers5

13

The fact that you're getting the funny output is a sure bet that your script has carriage return (CR) characters at the end of the lines, usually a symptom of using Windows editors that assume line endings should be CR/LF rather than just the standard UNIX LF (linefeed). That is causing error output like:

this_command_ends_hh<CR>: command not found

and because the CR is putting the cursor back at line start, it's overwriting some of it:

this_command_ends_hh<CR>
: command not found

making:

: command not foundh

Examine your script with od -xcb scriptname to check for CR (displayed as \r) characters, you can also pipe the script output through od -xcb to see the real output. For example is a file I created with hello followed by a carriage return on the one and only line:

0000000    6568    6c6c    0d6f    000a
          h   e   l   l   o  \r  \n
        150 145 154 154 157 015 012
0000007

You can see the CR (\r) in there.

If that is the problem, simply remove the CR characters such as piping it through tr -d '\r'.

Executing cat hello.txt | tr -d '\r' | od -xcb shows that you can get rid of it:

0000000    6568    6c6c    0a6f
          h   e   l   l   o  \n
        150 145 154 154 157 012
0000006

In your case, assuming your script is called freak.bash, you would use:

tr -d '\r' <freak.bash >newfreak.bash

and newfreak.bash would be the one without the offending characters.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
1

A tool you can use to understand what is happening in the execution of this script in order to debug is the command,

bash -x scriptname.sh
Jordan Dea-Mattson
  • 5,791
  • 5
  • 38
  • 53
sr01853
  • 6,043
  • 1
  • 19
  • 39
1

paxdiablo is almost certainly correct: you need to fix the line endings. But you also have an errant semi-colon in the first line. Instead of:

#!/bin/bash;

you want:

#!/bin/bash

without the trailing semi-colon.

William Pursell
  • 204,365
  • 48
  • 270
  • 300
0

I don't have a Centos 5 right now, but maybe... just maybe... bash isn't located at /bin? In FreeBSD, it's located at /usr/local/bin. In Cygwin, it's at /usr/bin. What's the output of this command:

which bash
simoncpu
  • 578
  • 5
  • 9
0

paxdiablo and William Pursell nicely explained what the problem is.

Now, please take the time to improve your script if you're going to distribute it.

NOT TESTED example:

#/bin/bash

ZIPFILE=http://192.168.1.2/cpplugin/LoginAlerthook.zip
CPANEL_LIBDIR=/var/cpanel/perl5/lib
MANAGE_HOOKS_CMD=/usr/local/cpanel/bin/manage_hooks

TMPFILE=`tempfile`

function exit_with_error(){
   echo "$*" >&2   # Write error messages to stderr!!
   exit 1
}

function at_exit(){
  [ -f "${TMPFILE}" ] && rm -v ${TMPFILE}
}

# Run at_exit function when script finishes
trap at_exit 0

echo "WELCOME TO ZOMBO.COM"

# Create lib directory if not exists, exit if not possible
if ! [ -d "${CPANEL_LIBDIR}" ]; then
     mkdir -p ${CPANEL_LIBDIR} || exit_with_error "Couldn't create required directory [${CPANEL_LIBDIR}]"
fi

wget ${ZIPFILE} -O ${TMPFILE} || exit_with_error "Couldn't download file"
unzip -d ${CPANEL_LIBDIR} ${TMPFILE} || exit_with_error "Couldn't unzip file"
chmod +x ${CPANEL_LIBDIR}/LoginAlert.pm || exit_with_error "Couldn't chmod file" 
$MANAGE_HOOKS_CMD add module LoginAlert

echo "End."

This is just a dirty example. Read the manpages to improve.

man bash
man tempfile
man wget
man unzip
man chmod
William Pursell
  • 204,365
  • 48
  • 270
  • 300
dschulz
  • 4,666
  • 1
  • 31
  • 31