Ubuntu version: Ubuntu 20.04.2.0 LTS
Shell: bash
I have a shell script which will be executed by root from root’s cron job.
But, even when I execute the script manually, it errors out saying the following
# ./fix_wifi.sh
./fix_wifi.sh: line 17: : command not found
./fix_wifi.sh: line 18: : command not found
Lines 17 and 18 are the ones with echo
and service network-manager restart
Providing the absoulte path names (/usr/bin, /usr/sbin) for these binaries in the script did not help.
So, I would like to source the startup files at the beginning of the script so that the script will be aware of the PATH variable (and other relevant variables)
But, for root user in Ubuntu, which startup file should I source ? I can see .bashrc
and .profile
files in root's home directory /root
.
#!/bin/bash
# Written by xyz
# Must be run as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
ConnectionStatus=$(nmcli networking connectivity)
#echo "$ConnectionStatus"
if [ "$ConnectionStatus" != "full" ]
then
/usr/bin/echo "Wifi found to be disconnected at " `date` " hence restarting the network manager..." | /usr/bin/tee -a /home/john/scripts/wifi_diagnostics.log
/usr/sbin/service network-manager restart
fi
Note:
I did forget to provide absolute path for date
command in Line 17. But, it is not very relevant here as line 18 containing service network-manager restart
still errored out despite providing full path (/usr/sbin)