0

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?

  1. In ~/.profile, I put

    sudo /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.

  2. 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 denied

    As a result the session will not be configured correctly.

    Is it because I didn't set sudo up, and how shall I use sudo for a command in /etc/profile?

Thanks.

Tim
  • 101,790

0 Answers0