was: Re: how to autorun script at startup as administrator? but now a new problem
Dave Stevens
geek at uniserve.com
Mon Dec 30 23:06:57 UTC 2019
On Sat, 28 Dec 2019 15:11:58 -0800
Dave Stevens <geek at uniserve.com> wrote:
snip!
>
> If mail="" works I can stop there I think.
>
> Dave
>
My original post asked about running a privileged command at bootup.
@reboot in the crontab does work for a non-privileged command but
fails if the command is sudo <command>. Not very surprising but doesn't
get me where I want to be.
I've been reading about rc.local. There is such a file on the system
with the default (null effect) contents. I think this will run as root
at boot time. The script I want to run will open a serial port and copy
edited serial data to a file using a node.js app called plantower to
get air pollution readings.
For specificity, here's the target script:
#!/bin/bash
# bash script to read data from a plantower 3003 on /dev/ttyUSB0
# dave stevens 19 March 2018
# make a file named by date and time then write
# timestamped PM2.5 data to it
filename=$(date +%F%T)
touch $filename
while true
do
datadate=$(date +%F%T)
echo -n $datadate >> $filename
echo -n " " >> $filename
~/node_modules/plantower/bin.js -m PMS3003 -d /dev/ttyUSB0 |
grep 5_a >> $filename echo -n "."
done
-------------- end script -------------
and sample output lines in the archive file:
2019-08-0819:21:36 concentration_pm2.5_atmos: 8 µg/m^3
2019-08-0819:21:37 concentration_pm2.5_atmos: 8 µg/m^3
2019-08-0819:21:38 concentration_pm2.5_atmos: 8 µg/m^3
2019-08-0819:21:39 concentration_pm2.5_atmos: 7 µg/m^3
2019-08-0819:21:40 concentration_pm2.5_atmos: 7 µg/m^3
----- and lots more like this --------------
What I don't understand is whether it is correct that the script (if
invoked through rc.local) will in fact run as root and if it does, will
sshd be running at the time the (infinite loop) script is running.
The anticipated situation is that there's a power failure at a distant
site where data collection is under way. I want a smooth recovery when
power is restored, a new file started and data being captured.
The script above does what I want but I need to ssh in and restart it
manually now.
So, do rc.local scripts in fact run as root? and during script
execution can I expect to have ssh access for updates and other system
admin tasks?
Dave
More information about the ubuntu-users
mailing list