linux - Issues with this sh script?
2014-07
Having issues executing this sh script...i don't see anything wrong with it, does someone else see something I screwed up?
echo "**************************************"
echo "*** ***"
echo "*** Updated Please Read ***"
echo "*** ***"
echo "**************************************"
sleep 3
echo "Will updating this OS cause any issues with a control panel? [y|n]"
echo " Answer No for Cpanel, Direct Admin, Webmin, Plesk, VZ."
# CP = 'n'
# read CP
# if [[ ! `echo $CP | egrep '(y|yes|n|no)'` ]]; then
#
# echo "Please answer with y or n:"
# read CP
# fi
echo "Testing for SELinux..."
selinuxenabled
if [[ $? = 0 ]]; then
echo "disabling SELinux..."
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
fi
echo "Initial time sync..."
ntpdate -b 204.123.2.72 > /dev/null 2>&1
if [[ -f /etc/redhat-release ]]; then
if [[ `egrep '(4\.[0-9]|\ 5\ |5\.[0-9]|\ 6\.[0-9])' /etc/redhat-release` ]]; then
CENT_VERSION=`cat /etc/redhat-release`
else
echo "This version of CentOS is not compatible with this script."
echo "Please use the old instructions."
exit 1
fi
else
echo "You are not running this script on CentOS."
exit 2
fi
if [[ `echo $CENT_VERSION | grep 4\.[0-9]` ]]; then
V=4
elif [[ `echo $CENT_VERSION | egrep '(\ 5\ |5\.[0-9])'` ]]; then
V=5
fi
echo "Updating Resolvers..."
Getting this error:
sh harden.sh
: command not found
**************************************
*** ***
*** Updated Please Read ***
*** ***
**************************************
sleep: invalid time interval `3\r'
Try `sleep --help' for more information.
Will updating this OS cause any issues with a control panel? [y|n]
Answer No for Cpanel, Direct Admin, Webmin, Plesk, VZ.
: command not found
: command not found
Testing for SELinux...
: command not found selinuxenabled
: command not found
Seems like something is mfunky with the formatting?
Turns out this was related to Windows adding \r characters...there is a utility called dos2unix
which fixes this, but I just did it myself by making the few changes in linux.
I have a script that runs (this works fine).
I'd like to produce logfiles from its output and still show it on screen. I have this command that creates three files from this blog:
((./fk.sh 2>&1 1>&3 | tee errors.log) 3>&1 1>&2 | tee output.log) 2>&1 | tee final.log
This does exactly what I want it to.
My only issue is that I create files in my script and copy them somewhere, and I'd like to copy these logfiles there too, which I can't do whilst this script is running. I also wanted to make it easier for any user to run my script, so I created another script to run this script. According to this post (see last post) I can put a .
before the script name and I can use variables assigned in my called script from the first script if I use them in the first.
It doesn't seem to work though and I can't figure out why or find alternative methods.
Can anyone help?
Please read the solution presented in the following link:
logging blocks of code to log files in bash @ stackoverflow.com
I've discovered that by using exec
I can achieve what I wanted with out the need for a second script, like so:
#!/bin/bash
exec 1>&2-
cmd1
cmd2
Thought it worth posting in case anyone happens upon this question!