LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-18-2013, 07:02 AM   #1
robsbots
LQ Newbie
 
Registered: Oct 2008
Posts: 26

Rep: Reputation: 1
Running a command at boot.


Hi all.
I think this should be a fairly simple question to answer.
I need to run a command as root, on boot. The command is 'ln /dev/ttyAMA0 /dev/ttyS1'
This command creates a link to a serial port. This is on the Raspberry Pi using the Raspbain release of Linux (Debian based).
I need this to run at boot, even if nobody has logged in.
What is the correct way to do this ?

Thanks

Rob
 
Old 01-18-2013, 07:07 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,795

Rep: Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888
you may insert this script into the init dir. Actually I can't remember the name of it on Pi, but usually it is /etc/init.d/rcX.d. So you can put a S99link script into that dir containing what you need (probably only that single line).
 
1 members found this post helpful.
Old 01-18-2013, 10:29 AM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,552

Rep: Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112
If the Pi has an /etc/rc.local file, that's generally where post-boot user scripts are placed.
 
1 members found this post helpful.
Old 01-18-2013, 11:04 PM   #4
robsbots
LQ Newbie
 
Registered: Oct 2008
Posts: 26

Original Poster
Rep: Reputation: 1
Talking It works

I have a working system.

I had a look at the file system and found rc0.d up to rc6.d, rcS.d and init.d. No rc.local.
After a quick search I found details on creating an rc script.

I created a file: "link_serial" in /dev/init.d/
In the file I placed :-
Code:
#! /bin/bash

ln -s /dev/ttyAMA0 /dev/ttyS1
exit 0
I then made the file executable
Code:
chmod 755 /etc/init.d/link_serial
I executed the command :-
Code:
update-rc.d link_serial defaults
This brought up a warning :-
script 'link_serial' missing LSB tags and overrides
but I don't think this is a problem in this case.

The above command created links in rc0.d to rc6.d but not rcS.d
As I understand it, I only really need a link in rc2.d. Should I remove the other links ?

After reboot, ttyS1 was available for use.

So I think this has got me going. If you can see any obvious errors or bad practice I'd love to know what I've done but otherwise I think I'm hot to trot.

So thanks for your help guys.

Top Job.

Rob
 
Old 01-19-2013, 10:07 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,795

Rep: Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888
Yes, probably you need it only in rc2.d. These links in the other dirs will not cause any problem, you can leave them or remove them as you wish (if you plan to use another runlevel you would rather keep it). Obviously it is not required in rcS.d, it is ok too.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] su - $user -c "command" starts shell instead of running command AlucardZero Linux - Software 3 08-28-2012 04:35 PM
[SOLVED] Running batch file does not produce same results as running command from Terminal nmuleski Linux - Newbie 9 12-30-2011 10:52 AM
Does Kornshell wait until one command completes before running the next command? ShaqDiesel Programming 4 09-11-2008 12:49 AM
Running wireless command on boot RoiSoleil14 *BSD 2 03-05-2006 08:22 PM
running a command at boot toddncl Linux - General 3 07-30-2004 10:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:13 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration