This is so simple but I cannot get it to work. I want to do a simple if else statement in ssh bash script. here’s my code below:
#!/bin/sh
echo -n "enter what type of logs. (ie. cpanel, apache) "
read type
if [$type == cpanel]
then
LOGTYPES ="error, access"
else
LOGTYPES ="error, access, suphp, suexec"
fi
echo -n "enter which log to tail (ie. $LOGTYPES) "
read logs
echo -n "enter last number of lines to view. (ie. 10, 5000 etc) "
read lines
tail -$lines /usr/local/$type\/logs/$logs\_log
I’ve tried everything and I keep getting this error:
[~]# /apachetail
enter what type of logs. (ie. cpanel, apache) cpanel
/apachetail: line 5: [cpanel: command not found
/apachetail: line 9: LOGTYPES: command not found
enter which log to tail (ie. )
I’ve tried the following methods, none work:
if [$type -eq cpanel]
if [$type -eq cpanel];
if [$type == cpanel];
if [$type = cpanel]
if [$type = cpanel];
if ["$type" = cpanel]
if ["$type" = cpanel];
if ["$type" == cpanel]
if ["$type" == cpanel];
if ["$type" -eq cpanel];
if ["$type" -eq cpanel]
Change
to
and
to
Any assignment has to be without spaces around the = (assignment operator).