Run Scripts as root at startup

Hi everyone,

I have some scripts which need to be run as root at startup. I have created a script and placed it in /etc/init.d/ and made a symlinks to rc5.d directory but still the script is not running.

Without knowing anything about your scripts, you might consider executing them via commands added to /etc/init.d/after.local

Ok thanks for the reply and I did try that. I have added this command

x11vnc -forever -display :0 

but it is not working

Does this thread help?

http://forums.opensuse.org/english/get-technical-help-here/network-internet/461205-setup-x11vnc-start-boot.html

No. Actually that is a sample command but I need to run some scripts as root like copying some files to /usr directories at startup

You’ll need to be more specific then. (I’m not about to playing guessing games).

Some reading for you:

systemd and using the after.local script in openSUSE 12.1/12.2/12.3 - Blogs - openSUSE Forums
openSUSE 12.3: Chapter 8. The systemd daemon

Thanks Deano. The first link is working for me. But I need to test my script.Once I finish checking my script I will get back to you.

And, at least tell which version of openSUSE you use. this is in this case important because of the differences between sysvinit and systemd. But it is allways good to tell this. When you let people do all the guessing of those things you could have told from the beginning, they might turn away from your problem.

And please have a look at

man 5 crontab

specialy to the @reboot feature.

BTW a command like

x11vnc -forever -display :0

is not likely to do what you want IMHO. At that moment in time there is no X-session running and thus display localhost:0 does not exist. Ans wjen such a session exists, it most probably did not allow you to open windows (or do anythinmg else) on it.

I don’t know what I am missing and here is the sample script that I want to run at startup as root.

#!/bin/sh
val1=$(< /restricted/MAC)
val2=$(/sbin/ifconfig | grep -i hwaddr | cut -d" " -f11)
if  $val1 == $val2 ] ;
then
echo "You have license"
echo $val1
echo $val2
else
echo "No Access"
echo $val2
echo $val1
remmina
fi




and I have added the following line to after.local in /etc/init.d/

sh /restricted/cmp.sh

but it is not working

How do you know it is not working? Where do you think all the output of those echo statements go to? You should catch that in a file in e.g. /tmp. When that file is not created, I think you can suggest yourself the script may not run at all. But without any prove, how do you know it is not running?

Actually it should open remmina if the MAC Address doesn’t match and no remmina window is opened but when I run the same script from the command line it opens remmina

Sorry I didn’t see yuor post earlier and I forgot to mention that I am using OpenSUSE 12.3

Running from the command line is of course a test that should be passed first. But that does not say much about a script being run in a different environment. It is not run from a login shell, thus many environment variables (PATH amongst them) are not set or set different. In any case, I would allways use absolute pathes and that would incluuse the path to remmina.

You must redirect all output from stdout and stderr to a file in e.g. /tmp. Else you will never be able to see what happens and what goes wrong.
Thus add something like

exec >/tmp/scriptoutput 2>&1

in the beginning of your script.

And I repeat, when you say that remmina is to open a window, where should that window be displayed. At boot there is no X-session running!

K got it .I will try that and get back to you.

On 2013-11-18 13:16, nishanth9042 wrote:

> K got it .I will try that and get back to you.

You can not open any application, be it graphical or text, that expects
to display things, or worse, use the keyboard. There is no session
opened yet.

You can “echo text” that might go to terminal number one.

About the symlinks under “/etc/init.d/”, they never worked in openSUSE,
not with old systemv, even less with new systemd. You would need to use
chkconfig. You have some reading to do on systemd.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

OK in that case If I want to run any command that needs display where should I be adding that command.

Add it to /etc/X11/xinit/xinitrc


.
.
.
#
# Add your own lines here...
#


# day planer deamon
# pland &

# 
# finally start the window manager
#
unset WINDOW_MANAGER STARTUP
exec $WINDOWMANAGER ${1+"$@"}

# call failsafe
exit 0

Refer to the following for more info

man xinit

On 2013-11-18 19:36, nishanth9042 wrote:
>
> robin_listas;2598528 Wrote:

>> You can not open any application, be it graphical or text, that expects
>> to display things, or worse, use the keyboard. There is no session
>> opened yet.

> OK in that case If I want to run any command that needs display where
> should I be adding that command.

Automatically? Text or graphics?

You probably need to enable autologin, and then use the autostart
feature of the desktop you use. Of course, it is a login session, anyone
present could use the computer.

On text mode you have two alternatives. One, is use autologin; there was
a recent thread about that recently, maybe I can find out which.

If you just want to print text to the screen, /maybe/ you can redirect
the output to one of the terminals beyond number 8. Could be 9, 11, 12
(not 10). Number 10 is used for log output, so you could use another one
without login prompt for a similar task.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

I want to run that command as a root.

I have a blog on how to get the after.local script to run as root where you could call other scripts:

systemd and using the after.local script in openSUSE 12.1 - Blogs - openSUSE Forums

Thank You,