I'm trying to run the following script at startup. I am able to see the notification only when I execute the script from the terminal, or when I run it as a program. So the issue is basically when run by the Startup Manager.
Script:
#!/bin/bash
Error log file
ERROR_LOG_FILE="$HOME/onedrive_mount_error_log.txt"
OUTPUT_LOG_FILE="$HOME/script_output_log.txt"
Redirect stdout and stderr to OUTPUT_LOG_FILE
exec > "$OUTPUT_LOG_FILE" 2>&1
Check if rclone is installed
if ! command -v rclone &> /dev/null; then
echo "rclone not found. Exiting script."
exit 1
fi
Mount OneDrive using rclone
rclone --vfs-cache-mode writes mount OneDrive: ~/OneDrive
if [ $? == 0 ] ; then
# If mount is successful, send a notification
/usr/bin/notify-send "OneDrive Connected" "Microsoft OneDrive successfully mounted."
else
# If mount fails, log the error
echo "Failed to mount OneDrive on $(date)" >> $ERROR_LOG_FILE
/usr/bin/notify-send "OneDrive Connection Failed" "Rclone failed to mount OneDrive."
fi
I'm using Ubuntu 23.10
Content of .confing/autostart/onedrive.sh.desktop
[Desktop Entry]
Type=Application
Exec=/home/ernesto/Documents/Scripts/test-message.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
X-GNOME-Autostart-Delay=10
Name[en_US]=Autostart Test message
Name=Autostart Test message
Comment[en_US]=Autostart Test message
Comment=Sync Automatic
journalctl --since='-10 minutes' --no-pager– Raffa Jan 07 '24 at 09:05org.gnome.Shell.Notificationsseems to start successfully ... Try monitoring by running in one terminal windowdbus-monitor | grep -10 notify-sendand in another terminal windownotify-send "My Title" "My Message"... You'll see the message being sent ... Now delay your script with e.g.sleep 120then re-login to start monitoring in the terminal and see if the message is sent ...dbus-monitoralone without| grep ...will give you more details. – Raffa Jan 07 '24 at 11:40dbus-monitorin the terminal and it will monitor messages going through the D-Bus message bus i.e. the route anotify-sendmessage takes until it appears in the notifications area ... It will monitor the messages sent by your script in real-time so you need to delay the execution of your startup script by enough seconds e.g.120so that you can open a terminal and start runningdbus-monitorbefore it starts executing ... I would recommend you try it first manually in two terminal windows so that you know how it works and what you should expect later when your script runs. – Raffa Jan 07 '24 at 12:22[ $? == 0 ]in your conditional will always evaluate the exit code of the previous command i.e.echo "rclone exited with = $?" > "$HOME/exit_code.txt"and that is probably not what you expect (you probably expect the exit code ofrclone ...) ... Start by making your shebang like this#!/bin/bash -xwhich will print command execution traces ... Redirect the output of your whole script to a file so that you can read it later. – Raffa Jan 07 '24 at 12:44/usr/bin/notify-send "Text Message" "My message"tostrace /usr/bin/notify-send "Text Message" "My message"and add one line before that line withexec &> "$HOME"/my.log... Re-login and wait for your startup script to execute and then runcat ~/my.logand copy the output to your question ... Notice a log file namedmy.logwill be created under your home directory (you can delete it after you copy the output into your question) – Raffa Jan 07 '24 at 15:20script_output_log.txt"is empty ( i thought you wanted to know this ) – Anima94 Jan 07 '24 at 17:05rclone --vfs-cache-mode writes mount OneDrive: ~/OneDrive(have you copied it from somewhere or edited your script on Windows) ... Runcat -A /home/ernesto/Documents/Scripts/test-message.shto know ... And in all cases try creating a new script file and type every line (don't copy) then use it instead. – Raffa Jan 07 '24 at 17:13Mount OneDrive using rclone
rclone --vfs-cache-mode writes mount OneDrive: ~/OneDrive /usr/bin/notify-send "OneDrive Connected" "Microsoft OneDrive successfully mounted."`
The notification stops. If I comment the line of rclone, like so: #!/bin/bash
Mount OneDrive using rclone
rclone --vfs-cache-mode writes mount OneDrive: ~/OneDrive
/usr/bin/notify-send "OneDrive Connected" "Microsoft OneDrive successfully mounted."
– Anima94 Jan 07 '24 at 17:41rclonejust takes a very long time to clone the files and that's what is delaying the notification ... as you know therclonecommand must finish (unless you send it to the background as you did by appending&) before the subsequent lines are parsed and executed by the shell. – Raffa Jan 07 '24 at 17:58