简体   繁体   中英

Script in a embedded linux

I believe that this is a silly question but is my first time in wich I do a script. I am working on Linux, in an embedded system, and I think that what I want to do is quite simple but for me is not working.

I need to set an ip, start the startx & server for graphical mode and give to my application permission and run it, so I try like this:

#!/bin/sh
#
#Start
#
echo "Start......"
ifconfig eth0 X.X.X.X
startx &
cd /home
chmod a+x myApplication
./myApplication
exit $?

And then I save my script like S80script and I put it in the /etc/init.d folder.

I ran it but after throw the startx server my application is not run.

How can I do this in a propertly way? There is another way for do this?

Thank you so much and sorry because maybe it is a beginner question.

If your application need to acess the XServer than you need to export the DISPLAY environment variable.

Try to run the application using:

DISPLAY=:0 ./myApplication

I would suggest you to install (for learning purposes) Linux on your laptop, and become familiar with Linux and scripting on your laptop. Then, replace during debugging phase the first line #!/bin/sh with #!/bin/sh -vx or #!/bin/bash -vx if you can run that script in a terminal. You could also use logger(1) in your script. Read the Advanced Bash Scripting Guide even if it is imperfect.

startx is configurable (read the linked man page), and is starting some client applications (configured in eg /etc/X11/xinit/xinitrc or in $HOME/.xinitrc ...); so you should start your $HOME/myApplication from that file.

BTW, you could invoke startx in some init script like /etc/rc.local or whatever is appropriate for your Linux distribution.

BTW, you almost certainly need a window manager (to be started after your backgrounded application, as the last command, probably in the same xinitrc ....).

At last, your embedded Linux distribution probably has some other files and scripts to start the network. You should configure your network parameters appropriately (on Debian and related, you could do that in /etc/network/interfaces )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM