DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 4 Weeks Ago
gustaf gustaf is offline
Port Guard
 
Join Date: Dec 2016
Posts: 39
Default 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
The variables exist to keep the script maintainable.

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; 4 Weeks Ago at 01:44 AM. Reason: formatting
Reply With Quote
  #2   (View Single Post)  
Old 4 Weeks Ago
ibara's Avatar
ibara ibara is offline
WR Slowest SNOBOL4 laptop
 
Join Date: Jan 2014
Posts: 515
Default

Like most other shell utilities, doas(1) returns 0 on success and >0 on failure. You can wrap that in a loop.
Reply With Quote
  #3   (View Single Post)  
Old 4 Weeks Ago
gustaf gustaf is offline
Port Guard
 
Join Date: Dec 2016
Posts: 39
Default

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
The loop is supposed to be for doas(1) only. I need some way to report an error and exit the script if the command fails.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT. The time now is 12:19 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick