Welcome!

Please read this important information about Spectre and Meltdown vulnerabilities.
Please read this important information about MX sources lists.

News
  • MX Linux on social media: here
  • Mepis support still here
Current releases
  • MX-17.1 Final release info here
  • antiX-17 release info here
New users
  • Please read this first, and don't forget to add system and hardware information to posts!
  • Read Forum Rules

is there a reliable way to grab exit codes when su? SOLVED

Here you can exchange scripts that you created or have permission to share with other users.
Message
Author
User avatar
GDixon
Forum Regular
Forum Regular
Posts: 358
Joined: Fri Nov 02, 2007 4:39 pm

is there a reliable way to grab exit codes when su? SOLVED

#1 Postby GDixon » Tue Nov 18, 2014 5:38 pm

su -c command really messes with exit codes.
I've tried getting them all ways from sunday using a case esac menu and failed. What happens is the last command that runs is what returns a exit code.
From my limited comprehension it's caused by running the command as su . Besides not running the command as su which is not an option is there a way to do it reliably?

I'm trying to grab the exit codes for freshclam 0 is ran correctly and updated / it outputs a 58 if the update fails due to no connection to the update site with a internet connection / and a 1 exit is a fail when i use the wrong password for su

I can get all the correct codes running the command all alone in a shell and then using echo $? after i do each one.
I get a 0 when it updates
I get a 1 when i use the wrong password
I get a 58 when i make the update fail by using a temporary gibberish update site
the 58 exit code prints to screen the site is off line unavailable or no connection

su -c freshclam is the command

I've even tried out putting the exit codes to a tmp file and then importing them back to the shell after su closes but I must not be doing that right since it has yet to work.
There has to be an easier way?
maybe it's time to learn more than just bash?

i'm really hating su -c now :)

In the past i have ran something requiring root as sudo with no password but I learned thats a security problem waiting to happen. Just how bad is it to run something as sudo like that?

User avatar
GDixon
Forum Regular
Forum Regular
Posts: 358
Joined: Fri Nov 02, 2007 4:39 pm

Re: is there a reliable way to grab exit codes when su? SOLV

#2 Postby GDixon » Tue Nov 25, 2014 7:55 pm

Found a way but is going to take some testing and tweaking to make it work.

I would like to know for sure the update worked or not by exit codes which i think will be more accurate and complete.

I'm finding case esac pretty versatile

Code: Select all

     case "$?" in

         0|1|58)

             case "$?" in

                   0) Update OK   # exit was ok make a log entry
                      ;;

                   1) Wrong Password
                      ;;     

                  58) exit code prints to screen the site is
                      off line unavailable or no connection
                      ;;

                    *) Unknown error for now
 
             esac


Return to “Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests