Is it a good idea to put a sudo command in a shell configuration file?
I have a bash script /home/t/bin/changeCpuFreq.sh
which can change my cpu frequency. The line 40 in my script is
echo $1 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
Which determines that running the script requires root privillege
I would like the script to run automatically every time I reboot Ubuntu or log in, and wonder where to put the command to run the script?
In
~/.profile
, I putsudo /home/t/bin/changeCpuFreq.sh 1600000
When I reboot Ubuntu, after logging in, Ubuntu reports an error
Error found when loading
/home/t/profile
.sudo: no tty present and no askpass program specified.
As a result the session will not be configured correctly.
In
/etc/profile
, I put the following at the end:/home/t/bin/changeCpuFreq.sh 1600000
When I reboot Ubuntu, I have an error before logging in:
Error found when loading
/etc/profile
:/home/t/bin/changeCpuFreq.sh
: line 40/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
: Permission deniedAs a result the session will not be configured correctly.
Is it because I didn't set
sudo
up, and how shall I usesudo
for a command in/etc/profile
?
Thanks.
/etc/profile
is never the right place to run a system-wide command on startup. – Ignacio Vazquez-Abrams Mar 31 '18 at 22:23~/.profile
, and addedsudo
, but got thesudo: no tty present and no askpass program specified
error. I am confused. – Tim Mar 31 '18 at 22:37