How to auto-run shell script made by me when TX2 system is booted.

Hi all,

I have a question.
How to auto-run shell script made by me when system is booted.
The source version is R28.1 and, OS is ubuntu 14.04

Could you let me know your idea?

Thanks & BR,

hello nwlee,

there are several script files will be running when system boot-up,
you can refer to below script file and adding some commands for testing.
thanks

/etc/profile.d/bash_completion.sh

Since R28.1 is Ubuntu 16.04, and you said 14.04, I am curious how much of this is custom? Also, details on specific scripts would be hard to advise on without knowing what the script will effect, e.g., if it is for the GUI environment, then perhaps the same location of scripting will be completely different (involves a particular user ID) versus something which is a generic service (does not involve a particular user ID).

Hi Jerry,

First of all, Ubuntu version is 16.04. Sorry for you give a confusion.

What am I try to do is picture streaming and detecting the people as soon as booting the TX2.

This is application that is applied with the Dron.

So, When I add my script /etc/profile.d/ dir, no problem to system?

Thanks & BR,

Would you mind if I add my script in the /usr/share/bash-completion script?

And, /usr/share/bash-completion/completion dir looks like busybox. Is it right?

Could you let me know your detail guide?

Thanks & BR,

About the profile.d directory…this is more or less standard among various Linux flavors. It isn’t just Jetsons or just busybox. Scripts in this directory are inherited by users of the bash shell. The base environment one inherits upon login to a bash prompt is set in “/etc/profile”. The scripts in “/etc/profile.d/” are a subset which “profile” loads. If bash loads, profile loads…if profile loads, “profile.d/*” loads. You can in fact look at “/etc/profile” and see the bash loop through and load those. Auto-complete is just a feature of bash which everyone inherits…your code could be inherited too if you want bash to inherit something.

Picture streaming and detection is probably more complicated. This is because GPU operations tend to require being bound to a GUI session (it doesn’t have to be a real GUI, it just has to have a buffer the GPU is bound to…it just happens that the most common buffer is the one from an active GUI login). You could run a virtual X server and a script in “/etc/rc.local” could bind to this X server via the DISPLAY environment variable…this would be valid for CUDA/GPU operations with no person actually logged in (the GPU doesn’t care if there is a real monitor attached so long as the buffer pretends to be a monitor). Whichever user owns the virtual X session needs to be a member of group “video” (which “nvidia” and “ubuntu” are already a member of).

I do not have advice on which virtual X server to use. Other people may have experience with this (remote desktop sharing does this and might be an alternative name to virtual X server).

In some cases crontab @reboot seems to be an option.

Hello Jerry,

As you mention post #2,

Could you give me a your example for adding some command in the /etc/profile.d/bash_completion.sh ?

I don’t know exactly.

I have a test following.

  1. Add the script with “TX2” to the /etc/init.d/ as below.

====================================================================
nvidia@tegra-ubuntu:~$ cat /etc/init.d/TX2
#!/bin/bash
#TX2_auto_run

export TX2_HOME=/home/nvidia/usb/mscnn-fusion-cudnn

case “$1” in
start) #on booting
echo -n “Starting TX2_auto_run : \n”
$TX2_HOME/test_new.sh start
echo
;;
stop) #on shutdown
echo -n “Shutting Down TX2_auto_run : \n”
$TX2_HOME/test_new.sh stop
echo
;;
restart) #on restarting
echo -n “Restarting TX2_auto_run : \n”
$TX2_HOME/test_new.sh restart
echo
;;
*)
echo “Usage : $0 {start|stop|restart}”
exit 1
esac
exit 0

  1. Change the permission

    $ sudo chmod 755 /etc/init.d/TX2

  2. Check the run-level in the /etc/init/rc-sysinit.conf

    env DEFAULT_RUNLEVEL=2

  3. Add symbolic link to the /etc/rc2.d/ and /etc/rc0.d/ dir

    $ ln -s /etc/init.d/TX2 /etc/rc2.d/TX2

    $ ln -s /etc/init.d/TX2 /etc/rc0.d/TX2

  4. Reboot the system

But, my script “test_new.sh” is not working well.

Could you let me know where was wrong my test?

Thanks & BR,

First, what is the content of the “test_new.sh” script? Does it understand arguments “stop”, “start”, and “restart”?

Also, are there any interactive login requirements in your script (e.g., does it require a GUI)?

Note that if you copy and paste a script in the forum, then mouse highlight the script, followed by clicking the “</>” (“code”) icon in the upper right, then the text will be quoted as source code (it displays with preserved tabs, has a scrollbar, so on).

Hi,

Thank you for your support.

I have test with post #2. The working is OK.

But, there is problem for the permission of the mounted camera disk.

How can I change the permission in script?

If sudo permission, I can’t input the password while the system is booted.

Could you let me know your advice?

Thanks & BR,

I see the example for bash_completion.sh in #2, I’m not sure what the content of your script is though.

When you say you need to fix permission, which file are you needing to change? Files in

"/etc/profile.d/" would be like this:
sudo chown root.root /etc/profile.d/the_file
# Equivalent to "ls -l" showing as "-rw-r--r--"
sudo chmod 644 /etc/profile.d/the_file

Note that there are cases where init will execute something directly, but other cases where it will “source” the file and essentially insert it inline with existing code…which means it takes on the permissions of the original script if the sourced file can be read…no execute on the script would be valid in this case since it is only sourced and not directly executed.

In the case of something involving a GUI or CUDA (both use the GPU) you need to associate with a “DISPLAY” environment variable which essentially names an X11 session that user is logged in to. Thus it goes back to the original question of what your program needs to execute…if you try to run a CUDA or other program needing a DISPLAY buffer and you have not associated with it (perhaps because nobody logged in to a GUI or you tried to associate with someone else’s GUI), then it will always fail with permission denied. Does your script use CUDA or GPU? If so, did you install a virtual desktop?

mount -o remount,rw /camera_mountpoint ?

Hi All,

Thanks for yours support. I apprecite it.

Permission problem has been solved with add NOPASSWD in the /etc/sudoers about my login id.

Camera mount problem was solved with add the mount routine in the my script.

But, there are the other problem.

That is what is not working python code. The error message as below.

================================================================================

Traceback (most recent call last):
File “/home/nvidia/usb/mscnn-fusion-cudnn/run_test.py”, line 22, in
import caffe
ImportError: No module named caffe

================================================================================

I think that export path is somethig wrong.

Could you let me know your advice?

For the reference, I have used CUDA and, no GUI environment. So, system is Ubuntu Desktop of the TX2 stand-alone.

Thanks & BR,

As a result, I want to do refering to the /home/nvidia/usb/mscnn-fusion-cudnn/run_test.py

Of course, run_test.py is working well in the /home/nvidia/usb/mscnn-fusion-cudnn because caffe module is imported.

What can I do in my /etc/profile.d/myscript?

Thanks & BR,

I am curious, does this same thing work with you manually running the script on command line (not in X and not with ssh forwarding)? Does the command line error change any when run from a GUI environment (CUDA might depend on this even if you do not graphically display anything)?