LinuxQuestions.org
Help answer threads with 0 replies.
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 11-17-2014, 09:19 PM   #1
django84
LQ Newbie
 
Registered: Nov 2014
Location: Rome, Italy
Distribution: Ubuntu, Busybox
Posts: 10

Rep: Reputation: Disabled
Question Automate commands just after boot in a Busybox environment


Hello everyone,
My name is Rick, and I'm glad to have found a nice forum like this ;D
I have a camera which loads Busybox. The camera has a Compact Flash card installed in it, which has one partition in it, formatted in the ext2 file system.

I would like the camera to automatically run these commands, just after boot has finished:
1. do a check on the /dev/hda1 file system, since sometimes when the partition is not unmounted by terminal (like after a power cycle or reset), Busybox warns about the FS flag.
"e2fsck -p -c /dev/hda1"

2. mount the hda1 partion:
"mount /dev/hda1 /mnt/0/

How can I automate these two commands to be executed as the last two of the boot process?
Thanks a lot!
 
Old 11-19-2014, 09:02 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,928

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
Without knowing anything about the camera's operating system it is difficult to say. My first guess would be to look in /etc/ and see if there is are any rcx.d directories. What ever directory except for rc0.d and rc6.d that has some files would be the one to add a script of your commands.

Files in that directory start with a SXX where xx is a number from 0 - 99. S99 would be the last process to start. I assume that the recording process would be the last to start and you really want to run your script before it that. You might be able to determine what process actually mounts /dev/hda1.
 
1 members found this post helpful.
Old 12-04-2014, 02:02 PM   #3
django84
LQ Newbie
 
Registered: Nov 2014
Location: Rome, Italy
Distribution: Ubuntu, Busybox
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thank you michaelk, sorry for my late response but I had to pause working on this project for a brief amount of time.
In the /etc dir, there are folders from rc0.d to rc6.d, and inside these folders there are several scripts that start with K or S; then there's a folder called rcS.d.

Inside it, there are these scripts: S05issue, S15var, S23urandom, S27resolv, S10mountall, S20mac, S25hostname, S94net.conf.
Now, Do I have to add a new script, something named S95user to this folder, or do I have to add my own code to the s94net.conf file?

What this script has to do is just to check the CF, mount it, then copy a file from the /bin folder to a folder in the CF where the snapshot are taken, and add this folder on the CF to the $PATH.
The snapshot will happen when a single board computer, connected to the camera through RS232, will execute the script copied during the boot.

Let me know if you need any additional info on the camera/system. Thanks again!
 
Old 12-04-2014, 08:30 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,928

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
You would create a new script S95xxx.

The output of the command runlevel should indicate the current runlevel which would indicate what rcx.d to add the script.
 
1 members found this post helpful.
Old 12-04-2014, 08:33 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Alternatively, if you have an /etc/rc.local file, you can put your commands in there.
 
Old 12-04-2014, 08:41 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,928

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
Possibly, since it is an embedded system may not have a rc.local
 
Old 12-04-2014, 08:44 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Quote:
Originally Posted by michaelk View Post
Possibly, since it is an embedded system may not have a rc.local
In my experience the usage of /etc/rc.local is about as hit or miss on embedded systems as it is on standard Linux distros. Either way, it's worth looking into. If it doesn't have one/can't use one, then put a custom script in /etc/init.d and link it into /etc/init.d/rc?.d, no harm no foul.

Last edited by suicidaleggroll; 12-04-2014 at 08:46 PM.
 
2 members found this post helpful.
Old 12-04-2014, 09:02 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,928

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
True
 
Old 12-04-2014, 10:34 PM   #9
django84
LQ Newbie
 
Registered: Nov 2014
Location: Rome, Italy
Distribution: Ubuntu, Busybox
Posts: 10

Original Poster
Rep: Reputation: Disabled
Guys, thanks a lot for your precious answers.
The camera starts in Run Level 3, so I went looking for rc3.d .
It contained these scripts:
S01respawnd S31ipsetd S41fpga S97ide.sh
S05sysklogd S33telnetd S87imgsrvd S98rick.sh
S20net.lo S35ftpd S90sync.sh S99launcher.php
S22net.eth0 S37ssh S92lighttpd
S30net.final S38net_mii S95usb

I created a sh script called S98user.sh, just between S97ide.sh and S99launcher.php .
The script is this:
Code:
#!/bin/sh                                                                                                               
# Startup script                                                                                                
                                                                                                                        
mount /dev/hda1 /mnt/0                                                                                                  

sleep 1                                                                                                                 
echo "HDA1 mounted"                                                                                                     

mount /dev/hdb1 /mnt/1                                                                                                  

sleep 10                                                                                                                
echo "HDB1 mounted"                                                                                                     

alias snap4='/mnt/0/pics/snap4.sh'                                                                                    
alias snap5='/mnt/1/pics/snap5.sh'                                                                                    

echo "Aliases snap4 e snap5 created"
I don't know why but the alias section of the script doesn't seem to work: if I enter the cmd snap4 after the boot, it says that the cmd is not found.
But if I manually enter the cmd to create the alias, the cmd "snap4" is then recognized.
Do I have to put the alias section of the script in another specific folder?
 
Old 12-05-2014, 10:06 AM   #10
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,087
Blog Entries: 10

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
@michaelk can you take a look at this other thread and let the OP know if anything's up they need to understand?

http://www.linuxquestions.org/questi...95#post5279995
 
Old 12-05-2014, 10:57 AM   #11
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Quote:
Originally Posted by django84 View Post
Guys, thanks a lot for your precious answers.
The camera starts in Run Level 3, so I went looking for rc3.d .
It contained these scripts:
S01respawnd S31ipsetd S41fpga S97ide.sh
S05sysklogd S33telnetd S87imgsrvd S98rick.sh
S20net.lo S35ftpd S90sync.sh S99launcher.php
S22net.eth0 S37ssh S92lighttpd
S30net.final S38net_mii S95usb

I created a sh script called S98user.sh, just between S97ide.sh and S99launcher.php .
The script is this:
Code:
#!/bin/sh                                                                                                               
# Startup script                                                                                                
                                                                                                                        
mount /dev/hda1 /mnt/0                                                                                                  

sleep 1                                                                                                                 
echo "HDA1 mounted"                                                                                                     

mount /dev/hdb1 /mnt/1                                                                                                  

sleep 10                                                                                                                
echo "HDB1 mounted"                                                                                                     

alias snap4='/mnt/0/pics/snap4.sh'                                                                                    
alias snap5='/mnt/1/pics/snap5.sh'                                                                                    

echo "Aliases snap4 e snap5 created"
I don't know why but the alias section of the script doesn't seem to work: if I enter the cmd snap4 after the boot, it says that the cmd is not found.
But if I manually enter the cmd to create the alias, the cmd "snap4" is then recognized.
Do I have to put the alias section of the script in another specific folder?
Aliases are specific to the shell you are running. That script was launched in a subshell on boot, and as soon as the script was done the subshell exited and the aliases disappeared. If you want your user to have some alias, then you need to put it in that user's .bashrc, .bash_profile, .profile, etc. or in the system-wide /etc/profile, etc.
 
Old 12-05-2014, 12:09 PM   #12
django84
LQ Newbie
 
Registered: Nov 2014
Location: Rome, Italy
Distribution: Ubuntu, Busybox
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thanks suicidaleggroll for your answer. I forgot to mention in my previous post that I've already tried to include the alias cmds in other files, as you can see below.
I put the alias cmds in the shrc file and I created another file called alias.sh inside /etc/profile.d .

The etc/profile file is this :
Code:
ENV=/etc/shrc                                                                                                           
HOSTNAME=`hostname`                                                                                                     
                                                                                                                        
export ENV HOSTNAME
This is the etc/shrc I edited :
Code:
alias snap4='/mnt/0/pics/snap4.sh'                                                                                    
alias snap5='/mnt/1/pics/snap5.sh'                                                                                    
                                                                                                                        
for FILE in /etc/profile.d/*.sh ; do                                                                                    
                                                                                                                       
if [ -x $FILE ]; then                                                                                                    
                                                                                                                       
. $FILE                                                                                                                  
                                                                                                                       
fi                                                                                                                       
done                                                                                                                    
                                                                                                                        
unset FILE
Inside the dir /etc/profile.d/ there are two scripts: path.sh and prompt.sh.

As an example, path.sh is this:
Code:
PATH=/usr/local/bin:/usr/bin:/bin                                                                                       
[ $(id -u) -eq 0 ] && PATH="/usr/local/sbin:/usr/sbin:/sbin:$PATH"                                                      
export PATH
I tried to put a script inside the dir /etc/profile.d/ named alias.sh:
Code:
alias snap4='/mnt/0/pics/snap4.sh'                                                                                    
alias snap5='/mnt/1/pics/snap5.sh'
but aliases are not recognized yet.
How do I include the alias cmds in the /etc/profile file?
Do I have to just insert the cmds after the "export ENV HOSTNAME" line?
 
Old 12-05-2014, 02:46 PM   #13
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Any of those should have worked. You will have to log out and back in to see anything, possibly even reboot the system.
 
Old 12-05-2014, 04:02 PM   #14
django84
LQ Newbie
 
Registered: Nov 2014
Location: Rome, Italy
Distribution: Ubuntu, Busybox
Posts: 10

Original Poster
Rep: Reputation: Disabled
I always rebooted the system after these edits. With busybox it doesn't seem to be possible to log out though.
Do you think I can try to include the alias cmds just after the "export ENV HOSTNAME" line in the /etc/profile?
 
Old 12-05-2014, 04:12 PM   #15
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Sure
 
  


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
How to automate installation commands? ASTRAPI Linux - Newbie 4 04-28-2014 04:33 PM
trying to automate wget commands Spawn10 General 5 09-22-2010 10:49 PM
How to automate 'net cat' commands ? b0nd Linux - General 2 08-27-2008 07:52 AM
Automate Commands at Boot up Ace Blackwell Linux - Newbie 1 04-21-2008 01:09 PM


All times are GMT -5. The time now is 06:38 PM.

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