Using "-s" to prompt for a string

This shows how to send a string to any number of devices.  In general, you can use this string any way you wish.  In this example, the string is used as a command line, and its output is trimmed to ten lines to fit into the status cell.  If you enter an invalid command, you will see the appropriate returned error value.

The r3_header line

The r3_header line is a special line that starts with the hash/pound symbol #.  This is interpreted by the shell processor as a comment.  The remot3.it Bulk Scripting server reads this line, if present, when you upload the file, and keeps track of parameters that will be asked for whenever the script is executed.

The "Send-String.sh" script uses the "-s" parameter in an r3_header comment line near the top of the file, as shown:

# r3_header, -s (Enter command)

 The information in parentheses should be interpreted as:

( Prompt string )
  • Prompt string = string to display when the dialog is shown

The given example shows the following dialog when you run "Execute Script".

mceclip0.png

Getting the information from the "-s" flag

Look for the following section near the end of the script.  The string parameter is base64 encoded by the Job Server and so must be base64 decoded in order to be used.

################################################
# parse the flag options (and their arguments) #
################################################
while getopts f:m:p:l:s: OPT; do
case "$OPT" in
s)
Log "OPTARG=$OPTARG"
commandString=$(echo "$OPTARG" | base64 --decode)
Log "Command: $commandString"
Status_A "Command:\n$commandString"
;;
esac
done
#===============================================================================
# down here we are executing the string on the command line, then sending status back about the command.
# users can choose to do other things here, such as doing something else with the string.

output=$($commandString)

For example, suppose I want to list the files in the /tmp folder using the command:

ls -l /tmp

When I execute this script, I type the command when prompted:

mceclip2.png

Then, check the checkbox to get updates as they happen:

mceclip3.png

After a few seconds, the status cells A and B fill in as shown:

mceclip1.png

 

========

Was this article helpful?
0 out of 0 found this helpful