Raspberry Pi OS - at command does nothing - linux

I have a Pi 3B+ with Pi OS (PRETTY_NAME="Raspbian GNU/Linux 10 (buster)")
I want to run a script at a certain time, using at command.
For testing purposes i have made a test1.sh, to open Chromium browser using pyautogui.
This file is located in /home/pi/test1.sh and contains the following:
#!/usr/bin/python3
import pyautogui
pyautogui.click(67, 20) #click Chromium icon
This .sh executes fine when clicked in the GUI and also when I run it typing ./test1.sh in the Terminal.
Trying to use at command does not work and yields the following:
pi#raspberrypi:~ $ at 11:50
warning: commands will be executed using /bin/sh
at> ./test1.sh
at> < EOT> (Here is where I type ctrl+D)
job 11 at Fri Nov 5 11:50:00 2021
At the specified time, nothing happens. I know it must be something I am doing wrong, but for the life of me I can not figure out what it is. Help?
Edit:
the first / in the shebang was missing in the post, but not in the file.
atq returns nothing
ps ax returns text below (cut for brevity)
PID TTY STAT TIME COMMAND
1 ? Ss 0:05 /sbin/init splash
2 ? S 0:00 [kthreadd]
3 ? I< 0:00 [rcu_gp]
date returns accurate date and time
cat /var/mail/pi returns the following:
Subject: Output from your job 11
To: pi#raspberrypi
Message-Id: <E1miwnI-0000tR-83#raspberrypi>
From: pi#raspberrypi
Date: Fri, 05 Nov 2021 11:50:00 +0100
sh: 49: ./test1.sh: not found
From pi#raspberrypi Fri Nov 05 12:05:00 2021
Return-path: <pi#raspberrypi>
Envelope-to: pi#raspberrypi
Delivery-date: Fri, 05 Nov 2021 12:05:00 +0100
Received: from pi by raspberrypi with local (Exim 4.92)
(envelope-from <pi#raspberrypi>)
id 1mix1o-0000xA-KG
for pi#raspberrypi; Fri, 05 Nov 2021 12:05:00 +0100
This suggests that the file is not there, but when I type ls it is clearly shown.
Using the full path /home/pi/test1.sh also returns nothing but the mail received states the following:
Subject: Output from your job 13
To: pi#raspberrypi
Message-Id: <E1mjHmv-0000NT-4B#raspberrypi>
From: pi#raspberrypi
Date: Sat, 06 Nov 2021 10:15:01 +0100
Traceback (most recent call last):
File "/home/pi/test1.sh", line 3, in <module>
import pyautogui
File "/home/pi/.local/lib/python3.7/site-packages/pyautogui/__init__.py", line 249, in <module>
import mouseinfo
File "/home/pi/.local/lib/python3.7/site-packages/mouseinfo/__init__.py", line 223, in <module>
_display = Display(os.environ['DISPLAY'])
File "/usr/lib/python3.7/os.py", line 678, in __getitem__
raise KeyError(key) from None
KeyError: 'DISPLAY'

As pointed out by #linuxfan in the comments:
The DISPLAY variable is not set.
problem was fixed by doing the following:
pi#raspberrypi:~ $ at now + 1 minute
warning: commands will be executed using /bin/sh
at> export DISPLAY=:0.0
at> /home/pi/test1.sh
at> <EOT>
job 17 at Sun Nov 7 10:55:00 2021

Related

How can I customise an ISO image of Webconverger with a Linux shell script?

I want to write a simple shell script that downloads the latest ISO image of Webconverger and changes the boot parameters of grub in /boot/live.cfg.
So this is what I have done so far:
#!/bin/bash
# 1. Download the ISO
wget https://build.webconverger.com/latest.iso
# 2. Mount the ISO and create a development folder
sudo mkdir /mnt/webconverger
sudo mount -o loop latest.iso /mnt/webconverger
mkdir devfolder
rsync -av /mnt/webconverger/ devfolder/
sudo umount /mnt/webconverger
sudo rm -r /mnt/webconverger
# 3. Change the file in the development folder.
chmod -R 777 devfolder/
rm devfolder/boot/live.cfg
echo \
"DEFAULT de
label de
menu label Start
kernel /live/vmlinuz
append initrd=/live/initrd.img boot=live skipconfig quiet splash components=gitfs net.ifnames=0 bootfrom=removable locale=de xkb=-layout%20de homepage=https://www.google.de/" \
> devfolder/boot/live.cfg
# 4. Create a new ISO image
mkisofs -o new.iso -l devfolder
rm -r devfolder/
The generated ISO does not boot.
I asume the reasons for the problem are, that I had to run the whole script with root privileges and that I need a more complex mkisofs command.
Does anybody know how to generate a proper ISO image for Webconverger with a shell script? Or is there an alternative method for the whole process? Something like ISO Master but for the command line?
Update
I have replaced the code snippets with the actual shell script. So it is easier to test. And here is the command line output (without the wget part):
mount: /dev/loop0 is write-protected, mounting read-only
sending incremental file list
./
boot/
boot/boot.bin
boot/boot.cat
boot/live.cfg
boot/syslinux/
boot/syslinux/ldlinux.c32
boot/syslinux/libcom32.c32
boot/syslinux/libutil.c32
boot/syslinux/splash.png
boot/syslinux/syslinux.cfg
boot/syslinux/vesainfo.c32
boot/syslinux/vesamenu.c32
live/
live/initrd.img
live/vmlinuz
live/filesystem.git/
live/filesystem.git/HEAD
live/filesystem.git/config
live/filesystem.git/description
live/filesystem.git/packed-refs
live/filesystem.git/shallow
live/filesystem.git/branches/
live/filesystem.git/hooks/
live/filesystem.git/hooks/applypatch-msg.sample
live/filesystem.git/hooks/commit-msg.sample
live/filesystem.git/hooks/post-update.sample
live/filesystem.git/hooks/pre-applypatch.sample
live/filesystem.git/hooks/pre-commit.sample
live/filesystem.git/hooks/pre-push.sample
live/filesystem.git/hooks/pre-rebase.sample
live/filesystem.git/hooks/pre-receive.sample
live/filesystem.git/hooks/prepare-commit-msg.sample
live/filesystem.git/hooks/update.sample
live/filesystem.git/info/
live/filesystem.git/info/exclude
live/filesystem.git/objects/
live/filesystem.git/objects/info/
live/filesystem.git/objects/pack/
live/filesystem.git/objects/pack/pack-1aa978c13266848f4644754d1875dc90ec4bfcdb.idx
live/filesystem.git/objects/pack/pack-1aa978c13266848f4644754d1875dc90ec4bfcdb.pack
live/filesystem.git/refs/
live/filesystem.git/refs/heads/
live/filesystem.git/refs/heads/master
live/filesystem.git/refs/remotes/
live/filesystem.git/refs/remotes/origin/
live/filesystem.git/refs/remotes/origin/HEAD
live/filesystem.git/refs/tags/
live/filesystem.git/refs/tags/initial-revision
sent 598,528,659 bytes received 726 bytes 239,411,754.00 bytes/sec
total size is 598,380,033 speedup is 1.00
I: -input-charset not specified, using utf-8 (detected in locale settings)
1.71% done, estimate finish Tue Jul 10 20:12:54 2018
3.42% done, estimate finish Tue Jul 10 20:12:54 2018
5.13% done, estimate finish Tue Jul 10 20:13:13 2018
6.84% done, estimate finish Tue Jul 10 20:13:08 2018
8.55% done, estimate finish Tue Jul 10 20:13:05 2018
10.26% done, estimate finish Tue Jul 10 20:13:03 2018
11.97% done, estimate finish Tue Jul 10 20:13:02 2018
13.68% done, estimate finish Tue Jul 10 20:13:01 2018
15.39% done, estimate finish Tue Jul 10 20:13:00 2018
17.10% done, estimate finish Tue Jul 10 20:12:59 2018
18.81% done, estimate finish Tue Jul 10 20:12:59 2018
20.52% done, estimate finish Tue Jul 10 20:12:58 2018
22.23% done, estimate finish Tue Jul 10 20:12:58 2018
23.94% done, estimate finish Tue Jul 10 20:12:58 2018
25.65% done, estimate finish Tue Jul 10 20:12:57 2018
27.36% done, estimate finish Tue Jul 10 20:12:57 2018
29.07% done, estimate finish Tue Jul 10 20:12:57 2018
30.78% done, estimate finish Tue Jul 10 20:12:57 2018
32.49% done, estimate finish Tue Jul 10 20:12:57 2018
34.20% done, estimate finish Tue Jul 10 20:12:56 2018
35.91% done, estimate finish Tue Jul 10 20:12:56 2018
37.62% done, estimate finish Tue Jul 10 20:12:56 2018
39.33% done, estimate finish Tue Jul 10 20:12:56 2018
41.04% done, estimate finish Tue Jul 10 20:12:56 2018
42.75% done, estimate finish Tue Jul 10 20:12:56 2018
44.46% done, estimate finish Tue Jul 10 20:12:56 2018
46.17% done, estimate finish Tue Jul 10 20:12:56 2018
47.88% done, estimate finish Tue Jul 10 20:12:56 2018
49.59% done, estimate finish Tue Jul 10 20:12:56 2018
51.30% done, estimate finish Tue Jul 10 20:12:55 2018
53.02% done, estimate finish Tue Jul 10 20:12:55 2018
54.72% done, estimate finish Tue Jul 10 20:12:55 2018
56.44% done, estimate finish Tue Jul 10 20:12:55 2018
58.14% done, estimate finish Tue Jul 10 20:12:55 2018
59.86% done, estimate finish Tue Jul 10 20:12:55 2018
61.56% done, estimate finish Tue Jul 10 20:12:55 2018
63.28% done, estimate finish Tue Jul 10 20:12:55 2018
64.98% done, estimate finish Tue Jul 10 20:12:55 2018
66.70% done, estimate finish Tue Jul 10 20:12:55 2018
68.40% done, estimate finish Tue Jul 10 20:12:55 2018
70.12% done, estimate finish Tue Jul 10 20:12:55 2018
71.82% done, estimate finish Tue Jul 10 20:12:55 2018
73.54% done, estimate finish Tue Jul 10 20:12:55 2018
75.24% done, estimate finish Tue Jul 10 20:12:55 2018
76.96% done, estimate finish Tue Jul 10 20:12:55 2018
78.66% done, estimate finish Tue Jul 10 20:12:55 2018
80.38% done, estimate finish Tue Jul 10 20:12:55 2018
82.08% done, estimate finish Tue Jul 10 20:12:55 2018
83.80% done, estimate finish Tue Jul 10 20:12:55 2018
85.50% done, estimate finish Tue Jul 10 20:12:55 2018
87.22% done, estimate finish Tue Jul 10 20:12:55 2018
88.92% done, estimate finish Tue Jul 10 20:12:55 2018
90.64% done, estimate finish Tue Jul 10 20:12:55 2018
92.34% done, estimate finish Tue Jul 10 20:12:55 2018
94.06% done, estimate finish Tue Jul 10 20:12:55 2018
95.76% done, estimate finish Tue Jul 10 20:12:55 2018
97.48% done, estimate finish Tue Jul 10 20:12:55 2018
99.18% done, estimate finish Tue Jul 10 20:12:55 2018
Total translation table size: 0
Total rockridge attributes bytes: 0
Total directory bytes: 30720
Path table size(bytes): 222
Max brk space used 2b000
292387 extents written (571 MB)
And this what I get in VirtualBox:
Click here!
So the full answer to the question is:
#!/bin/bash
# 1. Download the ISO
wget https://build.webconverger.com/latest.iso
# 2. Mount the ISO and create a development folder
sudo mkdir /mnt/webconverger
sudo mount -o loop latest.iso /mnt/webconverger
mkdir devfolder
rsync -av /mnt/webconverger/ devfolder/
sudo umount /mnt/webconverger
sudo rm -r /mnt/webconverger
# 3. Change the file in the development folder.
echo \
"DEFAULT de
label de
menu label Start
kernel /live/vmlinuz
append initrd=/live/initrd.img boot=live skipconfig quiet splash components=gitfs net.ifnames=0 bootfrom=removable locale=de xkb=-layout%20de homepage=https://duckduckgo.com nobrand" \
| sudo tee devfolder/boot/live.cfg
# 4. Create a new ISO image
sudo mkisofs -r -J -l -V "Webconverger" -b boot/boot.bin -c boot/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o new.iso devfolder
sudo isohybrid new.iso
sudo rm -r devfolder/
For some reason dd did not work for Webconverger images. Even the with the untouched latest.iso it was not possible to create a bootable USB flash drive. So I used Win32DiskImager.
What you want to do is to generate an El Torito bootable CD with an MBR in its first bytes.
mkisofs(8) needs some special options to create an "El Torito" bootable CD:
mkisofs -r -J -l -V "Webconverger" -b boot/boot.bin -c boot/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o new.iso devfolder
Explaination:
-r -J: Enable Joliet and Rock Ridge meta data.
-l: Allow long filenames.
-V: Set volume ID. Optional.
-b: Specify the "El Torito" boot image.
-c: Specify the "El Torito" boot catalog.
-no-emul-boot: Specify that this is an "El Torito" bootable CD.
-boot-load-size: number of 512 bytes sector to load (4 is what usually works)
-boot-info-table: modify the original boot image appending the Boot Info Table
Then, if you want to be able to just dd the file on a USB drive you will need to write an MBR onto the ISO:
isohybrid new.iso

Getting specific part of output in Linux

I have an output from a shell script like this:
aaa.sh output
Tue Mar 04 01:00:53 2014
Time drift detected. Please check VKTM trace file for more details.
Tue Mar 04 07:21:52 2014
Time drift detected. Please check VKTM trace file for more details.
Tue Mar 04 13:17:16 2014
Time drift detected. Please check VKTM trace file for more details.
Tue Mar 04 16:56:01 2014
SQL> ALTER DISKGROUP fra ADD DISK '/dev/rhdisk20'
Wed Mar 05 00:03:42 2014
Time drift detected. Please check VKTM trace file for more details.
Wed Mar 05 04:13:39 2014
Time drift detected. Please check VKTM trace file for more details.
Tue Mar 05 05:56:07 2014
GMON querying group 3 at 10 for pid 18, osid 27590856
GMON querying group 3 at 11 for pid 18, osid 27590856
I need to get the part, beginning from today's date:
Wed Mar 05 00:03:42 2014
Time drift detected. Please check VKTM trace file for more details.
Wed Mar 05 04:13:39 2014
Time drift detected. Please check VKTM trace file for more details.
Tue Mar 05 05:56:07 2014
GMON querying group 3 at 10 for pid 18, osid 27590856
GMON querying group 3 at 11 for pid 18, osid 27590856
You can get the date in the correct format like this:
today=$(date +'%a %b %d')
and then search for it like this:
grep "$today" aaa.sh
If there are lines from today without a date, such as your GMON lines, you could add -A to say how many lines after the match you want and use a big number:
grep -A 999999 "$today" aaa.sh
If you are on AIX and there is no -A option, use sed like this:
today=$(date +'%a %b %d')
sed -n "/${today}/,$ p" aaa.sh
Explanation:
That says store today's date in the variable today in the format "Wed Mar 05". Then search, without printing anything (-n) till you find that date, From that point on, till the end of file ($) print all lines (p).
I think I have an easy solution:
Get date to output the date in a format that would match the date in the file (check man date on formatting options). Since we don't want to match the hours/minutes/seconds we have to call date twice: once for the weekday/month/day half and once for the year half on the end of the full date. Between these two halves we match the horus/minutes/seconds with .* regex.
Then do:
aaa.sh | grep -E '`date --only-weekday-month-day`.*`date --only-year`' -A 999999
though I am using answer by NewWorld it can be modified as,
convert output of date similar to your file format
suppose in variable 'D'you get that output
sed '1,/${D}/d' aaa.sh
that will output all lines after match date match.
example: suppose you get D="Wed Mar 05 00:03:42 2014"
output will be as expected.
You can use
tail -n 7 filename
for getting the desired output . It will basically give you the last seven lines of the text file named filename .
For getting solution from today's date you can use :
k=$(date +"%a %b %d")
g=$(grep -nr "$k" in|cut -f1 -d:|head -1)
total=$(wc -l<in)
l=`expr $total - $g + 1
tail -n$l in
Try
sed -n '/Wed Mar 05/,$p' aaa.sh
Here -n means "don't print anything unless specified to".
First appearance of a line that matches the expression /Wed\ Mar\ 05/ till the end of the file, will be printed(p)"

How to remove terminal control escape sequences in the file?

I got a log from remote linux computer. It looks like:
2013-10-23T08:19:05+0300 Last login: Wed Oct 23 08:17:38 EEST 2013 from 10.9.167.55 on pts/0
2013-10-23T08:19:05+0300 Last login: Wed Oct 23 08:19:05 2013 from 10.9.167.55^M
2013-10-23T08:19:07+0300 ^[[?1034h-bash-4.1$ date
2013-10-23T08:19:07+0300 Wed Oct 23 08:19:07 EEST 2013
2013-10-23T08:19:08+0300 -bash-4.1$ ls
2013-10-23T08:19:08+0300 ^[[0m^[[01;34m99^[[0m #avail.info ^[[01;34mgmoTemp^[[0m raml21.dtd SNMP4JTestAgentBC.cfg
2013-10-23T08:19:08+0300 an_mainHost_localhost_20131023081654000136.xml #avail.info~ gsh.txt ^[[01;34mresults^[[0m
2013-10-23T08:19:09+0300 ^[[m-bash-4.1$ exit
2013-10-23T08:19:09+0300 logout
But it should be:
Last login: Wed Oct 23 08:17:38 EEST 2013 from 10.9.167.55 on pts/0
Last login: Wed Oct 23 08:19:05 2013 from 10.9.167.55
-bash-4.1$ date
Wed Oct 23 08:19:07 EEST 2013
-bash-4.1$ ls
99 #avail.info gmoTemp raml21.dtd SNMP4JTestAgentBC.cfg
an_mainHost_localhost_20131023081654000136.xml #avail.info~ gsh.txt results
-bash-4.1$ exit
logout
The messy codes are terminal control escape sequences, you can use command "infocmp xterm" and "man terminfo" to get more details.
My question is how can I remove these terminal control escape sequences in the file?
Thanks a lot!
Simple way to remove most parts of the control character is using the command below in vim:
:%s/<escape-key>\[[0-9;]*m/ /g
Press Ctrl+V followed by esc-key for the <escape-key> character above. Everything else is the same literal key as in your keyboard.
i use a pipe or direct sed like this
sed 's/[^[:print:]]\[[^a-zA-Z]*[a-zA-Z]//g' YourFile
I solved this issue using lots of regular expressions according to http://invisible-island.net/xterm/ctlseqs/ctlseqs.html

Real-time display of `date` changes on Linux

On an embedded Linux device that does not present /dev/rtc*, how can I set off a console window writing the value of the Real-Time Clock to the console, on the tick, every time it changes?
Results would be like:
$ **someCmd**
Mon Mar 14 16:43:22 UTC 2011
Mon Mar 14 16:43:23 UTC 2011
Mon Mar 14 16:43:24 UTC 2011
Mon Mar 14 16:43:25 UTC 2011
Mon Mar 14 16:43:26 UTC 2011
etc.
The device is armv5tejl running BusyBox v1.13.3.
Use the watch commad, try this is:
watch -n 1 date
I don't know how much the BusyBox shell supports, but in sh you could do something like this:
{ while true ; do date ; sleep 0.1 ; done } | uniq

one week information of alertlofile

I want to view the ORA errors in alertlogfile of past 7 (monday-sunday)days,
by writting in shell scripts.
Can anybody help me.
Thanks
Something like:
sed -n -e '/start_time/,/end_time/ {/ORA/ p}' logfile
or with awk
$ start="Fri Feb 27 08:00:00 2009"
$ end="Fri Mar 6 08:00:00 2009"
$ awk -v prev="$start" -v last="$end" '$0 ~ prev,$0 ~ last' logfile
A more sophisticated script looking for last date entries in ORA file is available here, but also at dba-oracle.com
This does not answer exactly your request but might give you some clues to start your own script.
I want the scripts which give output as follows (one week errors) and it should be mail to my id.
Sat Mar 14 10:30:51 IST 2009
ORA-01157: cannot identify/lock data file 2 - see DBWR trace file
Sat Mar 12 12:35:06 IST 2009
ORA-01110: data file 2: '/u02/oradata/Globe/undotbs01.dbf'
Sat Mar 10 09:54:05 IST 2009
ORA-27037: unable to obtain file status
Sat Mar 08 :15:02 IST 2009
ORA-1157 signalled during: ALTER DATABASE OPEN...
Sat Mar 07 12:35:51 IST 2009
ORA-01157: cannot identify/lock data file 2 - see DBWR trace file

Resources