Results 1 to 4 of 4
I'm a beginner at shell scripts and I need to learn a few more tricks to compete a task I have. I have created a very simple nautilus script to ...
- 07-15-2007 #1Just Joined!
- Join Date
- Nov 2006
- Location
- Tukwila, WA
- Posts
- 7
Error traping in nautilus scripts
I'm a beginner at shell scripts and I need to learn a few more tricks to compete a task I have. I have created a very simple nautilus script to archive some files onto my server. It is simply an SCP command. It does not run in a terminal and it provides no feedback (other than asking for a password). I would like to know that the process finished successfully (or more importantly, if it didn't). How do I trap errors and display them in a gnome dialog box?
Thanks
- 07-15-2007 #2
When you say "Nautilus script", I assume that you mean "Bash script"? Which is to say, it's a shell script, just you're running it from Nautilus.
Now then: the variable $? holds the return code of the last executed program. So if you check the value of $? just after you run scp, you'll get its return code. From scp's man page:
As far as popping up a dialog box, I'm coming up a bit dry. One option would be to write a Tcl/Tk script to do this, but it may be overkill. There's also the option of using dialog: you could end your script with:Code:The scp utility exits 0 on success, and >0 if an error occurs.
dialog creates an ncurses-based notification, but since we're popping up a new xterm, it should be alright.Code:exitstat = $? if [ $exitstat -eq 0 ]; then message=All Good else message=Error in Running fi xterm -e "dialog --title \"scp Exit Status\" --msgbox \"$message\" 0 0"
Check "man dialog" for more information.DISTRO=Arch
Registered Linux User #388732
- 07-19-2007 #3Just Joined!
- Join Date
- Nov 2006
- Location
- Tukwila, WA
- Posts
- 7
I found some other scripts use zenity for handling dialog boxes. I wrote this code:
However, I always get the "Archive Failed" result. I have confirmed that the scp was successful and that the command returned 0:Code:#!/bin/bash <scp command> exitstat = $? if [ $exitstat -eq 0 ] then zenity --info --text="Archive Successful" else zenity --info --text="Archive Failed" fi
All the references I've looked at indicate the if statement is well formed. Could I be missing anything else?Code:<scp command> exitstat = $? zenity --info --text=$exitstat
- 07-19-2007 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Remove the spaces around the "=" like this:Code:exitstat = $?
RegardsCode:exitstat=$?


Reply With Quote