LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 06-11-2011, 06:30 PM   #1
Dennola4
LQ Newbie
 
Registered: Jan 2009
Location: New Orleans
Distribution: Slackware, SalixOS, Puppy
Posts: 26

Rep: Reputation: 15
Need help writing basic bash script to toggle two i8kctl commands (fan speed hi/low)


I'm on a Dell Inspiron 6000. I installed i8kutils and it works. Fan speed reduces CPU temp from 50C to 44C. A start-up script invokes the i8k module: $ sudo /usr/sbin/modprobe i8k force=1 which creates /proc/i8k. The man page for i8kctl is straightforward: a few simple commands to read info from the aforementioned file.

So. I know nothing about writing even basic bash scripts. I gave it a go here but I know this is way wrong. Would anyone like to help a guy out? This is my starting point (don't laugh):

Code:
#!/bin/bash
# script to toggle fan speed low/high
if /proc/i8k | grep "-1 1"
then sudo /usr/bin/i8kctl fan - 2
killall Terminal
else sudo /usr/bin/i8kctl fan - 1
killall Terminal
exit 0
fi
Thanks in advance.

o_O

Last edited by Dennola4; 06-11-2011 at 10:52 PM.
 
Old 06-11-2011, 07:08 PM   #2
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
I wouldn't try to run sudo within the script, I think you'd be better off with "sudo thatScriptName".

I'd also recommend a look at the bash man page ("man bash") along with this
 
Old 06-11-2011, 08:26 PM   #3
Dennola4
LQ Newbie
 
Registered: Jan 2009
Location: New Orleans
Distribution: Slackware, SalixOS, Puppy
Posts: 26

Original Poster
Rep: Reputation: 15
Will do. Thanks.
 
Old 06-11-2011, 08:43 PM   #4
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
I'm unfamiliar with the laptop model or the utility, but here are some ideas.

Scripts often are run in non-interactive mode and in the background. You don't need to run the killall Terminal command. Such a command in a script would close any Terminal session that is open under the same user account. That likely would be a bummer.

If the /usr/bin/i8kctl path is correct, then you should not need to run sudo or run the command as super user.

Are there any related temperature sensors you can monitor to automatically control fan speeds? If there are then you can run the script in the background. Use the sleep command to idle until the next sampling of the temperature sensor. If the temperature exceeds a certain level then run the fan at speed 1. If the temperature exceeds a higher level then run the fan at speed 2. And vice-versa.

Try searching the web for shell scripts controlling fan speeds with the i8kctl command. That would provide you with a reasonable foundation to study shell scripting and you then would not feel as lost. A quick check of the web shows there are discussions about that module so some shell scripts likely exist too.
 
Old 06-11-2011, 10:49 PM   #5
Dennola4
LQ Newbie
 
Registered: Jan 2009
Location: New Orleans
Distribution: Slackware, SalixOS, Puppy
Posts: 26

Original Poster
Rep: Reputation: 15
Thumbs up

@Woodsman:

I spent all last night and my entire day today Googling scripts related to i8k, fan speed, etc. The only thing I could find that came close was the one I used as a template for the "script" I posted. My attempts to tweak it demonstrate my bash scripting ignorance. Oh well, I'll learn.

I spent awhile in /etc/sensors3.conf trying to identify each chip by name and learn its function, but then I found a program called i8kmon which runs as a daemon and controls fan speed based on sensor readings, so I could more easily go that route. Fact is that between GKrellM and hddtemp I have a pretty good sense of when I'm running hot and I'd rather be able to toggle the fan manually.

Thank you for pointing out the misuse of sudo. Late night error in logic based on the fact that the executable binary is in /usr.

Aaaanyway, Shador of SalixOS was kind enough to bang-out a working script for me. Because I would rather not be a useless leech, I plan to study this script using the links offered here until I understand exactly why it works. Thanks for your input, as always. Slackware is the very best thing ever. :-)

Code:
#!/bin/sh

if [ "x$(i8kfan speed)" == "x-1 1" ]; then
i8kfan - 2
else
i8kfan - 1
fi
-Dennis in New Orleans
 
Old 06-12-2011, 10:33 AM   #6
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
Quote:
I spent all last night and my entire day today Googling scripts related to i8k, fan speed, etc.
Been there done that. Linux based systems provide wonderful freedom but the cost is many hours looking for solutions to (sometimes) mundane tasks.

Quote:
Oh well, I'll learn.
I don't remember my first shell script. I had some programming experience and had written "batch files" in MS-DOS going back to the 1980s. The transition was not overwhelming for me. I empathize with those who lack any programming experience. One nice thing about shell programming is the top-down structure. There is no "goto" command, which lends well to not creating "spaghetti code." I do not consider myself a shell script wizard, but I never think twice about writing a script. Necessity is the mother of invention and that is the foundation upon which I learned to write shell scripts. I have more than 200 shell scripts in my /usr/local/(s)bin collection. Some are short, some are extensive, most are in between. Most serve a unique purpose, following the old adage of "one tool one job." The best approach to learn shell scripting is just starting writing scripts. I have spent more hours than I can count studying online how other people have approached similar scripts. Don't worry about technique. Technique will come as you write more scripts. If the script functions as you wish then smile and enjoy the sunshine. Function should prevail over form.

Glad you got something working.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
Bash script to toggle a daemon (here proftpd) dEM0nsTAr Programming 17 01-07-2010 09:17 PM
how to know fan speed using i2c commands on IA64 deedhnd Linux - General 1 04-04-2009 11:15 AM
Low CD-R writing speed? MasterOfTheWind Linux - Hardware 3 04-11-2006 03:36 AM
howto: control CPU fan speed and Northbridge fan speed? hedpe Linux - Software 2 04-18-2005 02:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 08:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration