I have this little scripts (following) that harvests CPU frequency and gives it a cute format.
The only problem is that it has to be run as root because of access to files readable only by root.
I'd like it to work for normal users. Actually, I'm not that much interested into finding an extra solution for this special case but a general way to solve this kind of problem (running a script as a user that reads files with root only permissions)
What I've tried that didn't work :
- Using suid on the script file
- chmod a+r on the files (file acces is reset at reboot, it's in /sys)... Yeah, I could have a script to chmod after every boot but I don't like it !
Here's the script :
Anyone has a suggestion ?
# Prints CPU Frequency scalling
#Check that the script is run as root
if !( test `id -u` -eq $ROOTID ) then
echo "Seul root peut exécuter ce script" >&2
#Make sure the path to the info exists
if !( test -d "$MAINPATH" ) then
echo "Impossible de trouver $MAINPATH" >&2
#Make sure the CPU enumeration exists
if (! test -f "$ENUMFILE" ) then
echo "Impossible de trouver l'énumération de CPU $ENUMFILE" >&2
#Formats the CPU enumeration so it's easy to process
CPUNUMS=`cat "$ENUMFILE" | sed -r -e 's/-/ /'`
echo "Fréquence de CPU :"
#Iterate on the CPU enumeration
for CPU in $CPUNUMS
#Directory for a particulare CPU
#Makes sur this CPU has it's directory
if !( test -d "$CPUDIR" ) then
echo "Impossible de trouver le sous répertoire $SUBDIR" >&2
#Files that contain the info
#Makes sure the frequency file exists
if !( test -f $FILE ) then
echo "Impossible de trouver le fichier $FILE" >&2
#Makes sure the governer file exists
if !( test -f $GOVFILE ) then
echo "Impossible de trouver le fichier $GOVFILE" >&2
#Read the values
#Formats (yep, I do have CPUs under 1 MHz ehehehe!)
if ( test $FREQ -ge 1000 ) then
FREQ=`expr $FREQ / 1000`
UNITS = "KHz"
echo " CPU $CPU : $FREQ $UNITS ($GOV)"
Have a nice day,