Rahul Bohare
Rahul Bohare

Reputation: 831

Startup shell script not producing output

I am working with Ubuntu 16.04 on an NVIDIA TX2 system and have a shell script launcher.sh containing the following commands:

#!/bin/sh cd /home/nvidia sudo python test.py >> /home/nvidia/test_output.txt,

basically implying to store the output of test.py in test_output.txt.

The test.pyhas one line: print "Testing startup script!"

I want this script (and more complicated scripts later on) to run automatically when the system boots up. To this end, I added it to the Startup Applications with the command /home/nvidia/launcher.sh and rebooted the system. The file test_output.txt is indeed created but there is no output written in it. I tested the script from the terminal and it works fine.

How do I make this to work from Startup Applications?

Upvotes: 0

Views: 86

Answers (1)

Murphy
Murphy

Reputation: 3999

Init scripts often don't have the complete environment initialized, e. g. PATH. In order to be executed you better provide the complete paths to commands.

On the other hand sudo is unnecessary here, as you obviously don't do anything that needs root permissions. If you need it, be aware that sudo is asking interactively for a password, which stalls the execution of the script, if the command you try to execute with it isn't explictely permitted in /etc/sudoers.

Provided test.py is located in /home/nvidia, and python in /usr/bin, the script should read

#!/bin/sh

cd /home/nvidia
/usr/bin/python test.py >> test_output.txt

And if you want to add error output to the outfile, which may be useful for debugging, make the last line

/usr/bin/python test.py >> test_output.txt 2&>1

or for a separate error log

/usr/bin/python test.py >> test_output.txt 2> test_error.log

Upvotes: 2

Related Questions