Network Shell Scripting Cheat Sheet. Syntax. Description. Examples / Comments. #!/bin/nsh. Identifies script as NSH script. This should be the first line of a NSH
Network Shell Scripting Cheat Sheet. Syntax. Description. Examples / Comments. #!/bin/nsh. Identifies script as NSH script. This should be the first line of a NSH
Network Shell Scripting Cheat Sheet. Syntax. Description. Examples / Comments. #!/bin/nsh. Identifies script as NSH script. This should be the first line of a NSH
Network Shell Scripting Cheat Sheet. Syntax. Description. Examples / Comments. #!/bin/nsh. Identifies script as NSH script. This should be the first line of a NSH
#! / bi n/ nsh Identifies script as NSH script This should be the first line of a NSH script when run on a UNIX/Linux host to identify it as NSH. # Comment # My NSH scr i pt # Out put s syst emi nf or mat i on echo Prints output (from the command line) host %echo `host name` Myser ver
/ / @ Shortcut to name of current host (from the command line) host %cp / / @/ c/ t est f i l e / / host / c/ t est f i l e
$NSH_RUNCMD_HOST Contains the name of the name of the current host when used with NSH scripts run via runscript HOST=$NSH_RUNCMD_HOST echo Host i s $HOST $NSH_RUNCMD_DI R Contains the current NSH Path PATH=$NSH_RUNCMD_PATH echo Pat h i s $PATH $? Returns output code of previous command (from the command line) host %cp t est . x t est 2. x cp: Unabl e t o access f i l e t est . x: No such f i l e or di r ect or y host %echo $? 2
(in a script) cp t est . x t est 2. x i f $? ne 0 t hen echo Copy f ai l ed exi t 1 Fi
$1 First parameter passed to the script Following example sets FILE equal to first parameter
FI LE = $1 $2 Second parameter passed to the script Following example sets PATH to second PATH = $2 Network Shell Scripting Cheat Sheet parameter $* Reference to every parameter passed to the script (often used when a list of hosts is passed to the script).
Ex: Reports Collect Agent Logs script. echo $* host 1 host 2 host 3 [ ! f <f i l e> ] Checks to see if a file exists (Use [! f <file>] to see if a file doesnt exist) (from the command line) host %[ - f / / @/ c/ WI NNT/ wi n. i ni ] host %echo $? 0 host %[ - f / / @/ c/ WI NNT/ wi nx. i ni ] host %echo $? 1 [ - d <di r ect or y> ] Checks to see if a directory exists (Use [! d <directory>] to see if a directory doesnt exist) (from the command line) host %[ - d / / @/ c/ WI NNT ] host %echo $? 0 host %[ - d / / @/ c/ WI N ] host %echo $? 1 f or X i n $X. . do. . done Used to loop through a list, performing the same actions on each item. f or HOST i n $* do echo $HOST done f or each X i n $X. . {. . } Similar to example above f or each HOST i n `cat $HOST_LI ST` { echo HOST } i f . . t hen. . el se. . f i Used to check conditions, and perform actions depending on results. i f [ ! d / t mp/ bl ade] t hen mkdi r / t mp/ bl ade el se echo Di r ect or y al r eady exi st s. f i > Redirect output to a file echo $HOST_LI ST > / c/ out put f i l e. l og >> Append output to a file echo $RESULT >> / c/ r esul t s. t xt uname Prints OS Version (from the command line) Network Shell Scripting Cheat Sheet host %uname Wi ndowsNT exi t Exits a script (see example below) exi t 1 aut ol i c Licenses a server aut ol i c <user name> <passwor d> host 1 [ host 2 . . . host n] bl quer y Used to query BladeLogic objects from the command line, such as the registry, local users & groups, software installations, and more (from the command line) host %bl quer y h wi n1 e r eg_val ue_exi st s ( " HKEY_LOCAL_MACHI NE\ \ SOFTWARE\ \ I NTEL\ \ Cur r ent Language" ) '