|
OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below. |
|
Thread Tools | Display Modes |
|
|||
doas in shell script ?
Hello everyone,
I'm trying to run this line in a shell script: Code:
doas dd if=${dldir}/install${vers}.fs of=/dev/rsd1c bs=1m Normally, I would just add a restrictive permit nopass gustaf cmd... args... line to /etc/doas.conf, but doas.conf(5) doesn't recognize variables and doas(1) throws a syntax error.If I run this line in the script and doas fails, I have to re-run the entire script since doas doesn't have any option for re-trying after password failure. Is there a way to create a loop (or something else) that will coax doas into re-asking for a password after a failed attempt so that the script can carry on? Thanks Last edited by gustaf; 20th October 2017 at 01:44 AM. Reason: formatting |
|
|||
Like most other shell utilities, doas(1) returns 0 on success and >0 on failure. You can wrap that in a loop.
|
|
|||
There are two exit codes and therefore, two possible points of failure:
doas and the command .Wrapping an exit code test in a loop does what I expect -- until doas(1) succeeds (exit 0), but the command fails (exit >0). The command failure is reported correctly, but the program is stuck in an infinite loop because the exit code for the command is not zero. To test this, I made a simple script: Code:
# Write a trace for each command. set -x doas ls ~/NoDirectory until [ $? -eq 0 ] do doas ls ~/NoDirectory done echo 'Script successfully completed!' OUTPUT: # + doas ls /home/gustaf/NoDirectory # doas (gustaf...) password: # ls: /home/gustaf/NoDirectory: No such file or directory # + [ 1 -eq 0 ] # + doas ls /home/gustaf/NoDirectory # doas (gustaf...) password: # ls: /home/gustaf/NoDirectory: No such file or directory # + [ 1 -eq 0 ] # + doas ls /home/gustaf/NoDirectory # doas (gustaf...) password |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
ask for a shell script | Simon | Programming | 5 | 27th April 2010 01:07 AM |
shell script with zenity | bsdnewbie999 | OpenBSD General | 5 | 24th April 2009 02:37 AM |
incrementing within a shell script? | spiderpig | Programming | 5 | 29th September 2008 08:12 PM |
Shell Script. | bsdnewbie999 | Programming | 21 | 15th July 2008 07:54 AM |
shell script with input | c0mrade | Programming | 5 | 13th July 2008 04:33 AM |