niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » *nix » Linux » Distributions » Suse
A simple bash script
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
JPB
*nix forums addict


Joined: 24 Feb 2005
Posts: 86

PostPosted: Fri Jul 21, 2006 2:19 am    Post subject: A simple bash script Reply with quote

I've finally managed to set lirc up to work with a homebrew serial port
receiver on my SUSE 10.1 machine. Now I need some small help with a
start up script to get the module to load properly.

The lirc_serial module is to be loaded on startup; however as the
serial port is recognized first during the boot up sequence, it becomes
"busy" and the module cannot be loaded. This has to be overcome
manually after user login by the following sequence of events (run as
root):

rclirc stop
setserial /dev/ttyS0 uart none (release serial port)
modprobe lirc_serial
rclirc start

I need to put this sequence of commands into a simple bash script, so
they do not have to be run manually each time the computer is
restarted. I realize that to write a script like this is probably
trivial, but as I have had no experience with this, I was hoping
someone here may be willing to show me how to do it. Also, which
directory are such scripts to be placed in, in order to run (on SUSE
10.1, that is)?

Thanks for any suggestions.

John B
Back to top
Lawrence D'Oliveiro
*nix forums Guru


Joined: 25 Mar 2005
Posts: 723

PostPosted: Fri Jul 21, 2006 5:39 am    Post subject: Re: A simple bash script Reply with quote

In message <1153448380.493955.42590@i3g2000cwc.googlegroups.com>, John
Bayley wrote:

Quote:
The lirc_serial module is to be loaded on startup; however as the
serial port is recognized first during the boot up sequence, it becomes
"busy" and the module cannot be loaded. This has to be overcome
manually after user login by the following sequence of events (run as
root):

rclirc stop
setserial /dev/ttyS0 uart none (release serial port)
modprobe lirc_serial
rclirc start

I need to put this sequence of commands into a simple bash script, so
they do not have to be run manually each time the computer is
restarted.

Put the commands, exactly as you would type them, in the
file /etc/init.d/boot.local. You'll see comments already in that file
explaining what it is for.
Back to top
houghi
*nix forums Guru


Joined: 22 Feb 2005
Posts: 6233

PostPosted: Fri Jul 21, 2006 11:12 am    Post subject: Re: A simple bash script Reply with quote

John Bayley wrote:
Quote:
This has to be overcome
manually after user login by the following sequence of events (run as
root):

rclirc stop
setserial /dev/ttyS0 uart none (release serial port)
modprobe lirc_serial
rclirc start

I need to put this sequence of commands into a simple bash script, so
they do not have to be run manually each time the computer is
restarted. I realize that to write a script like this is probably
trivial, but as I have had no experience with this, I was hoping
someone here may be willing to show me how to do it. Also, which
directory are such scripts to be placed in, in order to run (on SUSE
10.1, that is)?

That is easier then you think:

#!/bin/bash
rclirc stop
setserial /dev/ttyS0 uart none
modprobe lirc_serial
rclirc start

Now you do a 'chmod +x restart-linc (asuming you named it like that). Pu
this file in /usr/local/sbin and you wil be able to run it as root.

Now what you can also do run it as one specific user. That way you won't
be needing to become root each and every time. I will asume that the
user is john. Add the following line to /etc/sudoers:
john ALL=NOPASSWD: /usr/local/sbin/restart-linc

You can now do 'sudo /usr/local/sbin/restart-linc'.
This however means that you need to run /usr/local/sbin/restart-linc
instead of just restart-linc. Do the followingas john:
ln -s /usr/local/sbin/restart-linc ~/bin/restart-linc
Add ", /home/john/bin/restart-linc" to the line in /etc/sudoers.
You need to open a new terminal to let this become active.

This means you can do 'sudo restart-linc'. That is shorter.
Are we there yet? No. CLI is so much fun. Smile Instead of the above, you
can so something else as well (No need to remove the above)
In ~/.bashrc you add the following line:
alias restart-linc="sudo /usr/local/sbin/restart-linc"
You need to open a new terminal to let this become active.

Now there is even more to do to make your live easier if you have a GUI.
Make a button with the command `sudo /usr/local/sbin/restart-linc`.
Every time you click on it, it should run the command.

If for some reason 'john' can't run it, you most likely need to use the
full path in the script. e.g. `/usr/sbin/rclirc stop`.

The disadvatage of the GUI solution is that you won't see if there were
any probems. You can solve this by running:
`aterm -c sudo /usr/local/sbin/restart-linc` instead AND add some lines
at the end of the script that will pause it at the end. How to do that I
leave as an exersice to the reader: http://www.tldp.org/LDP/abs/html/
--
houghi Please do not toppost http://houghi.org
Let's not be too tough on our own ignorance. It's the thing that makes
America great. If America weren't incomparably ignorant, how could we
have tolerated the last eight years? -- Frank Zappa, in 1988
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Sun Nov 23, 2008 2:48 pm | All times are GMT
navigation Forum index » *nix » Linux » Distributions » Suse
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts does squid 2.6 support setting cache_peer port in redirec... Victor Tsang Squid 0 Fri Jul 21, 2006 8:16 am
No new posts mail script eeb4u@hotmail.com shell 3 Fri Jul 21, 2006 5:50 am
No new posts ECPG (usage of simple select statement) Jasbinder Bali PostgreSQL 0 Fri Jul 21, 2006 3:28 am
No new posts Simple ?? NIS problem Gary Solaris 4 Thu Jul 20, 2006 10:27 pm
No new posts Simple Relay Problem Stephen Hargrove Postfix 3 Thu Jul 20, 2006 6:32 pm

Anime | Discount Magazines | Magic The Gathering Cards | Mortgage Calculator | Loans
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1634s ][ Queries: 16 (0.0810s) ][ GZIP on - Debug on ]