You can simplify your scripts by leveraging environment variables.
The following table provides a simple list of the environment variables and the command line options they replace.
Table 1 FSCLI variablesVariable |
Value |
Option that the variable replaces |
PDS_USER |
The user account ID. |
-u |
PDS_HOST |
The name of the Oracle FS System. The value of PDS_HOST can be the DNS name or the IP address of the system. |
-oracleFS |
PDS_TIMEOUT |
Time in seconds. |
-timeout |
PDS_KEY_IN_STDIN |
Oracle FS System session identifier. |
-sessionKey |
For specifics on how each command uses the environment variables, see the
Oracle Flash Storage System CLI Reference.
The following table lists two examples. One example of scripting without environment variables and one example of scripting with environment variables.
Important! You must place your scripts in the same directory as the FSCLI binary.
Table 2 Environment variables scripting examplesScripting without variables |
Scripting with variables |
#! /usr/bin/env bash
# example script using fscli credentials to add clone,
# call backup, and delete clone
# verify command line arguments
if [ $# -ne 5 ]; then
echo "Usage: ./$(basename $0) <ofs-user-account> <ofs-name-or-ip> <source-lun-fqn> <backup-server-fqn> <clone-lun-name>"
exit 1
fi
# prompt for password
read -s -p "Password: " password
echo ""
echo ""
# check overall system status
command="./fscli system -list -status -u $1 -oraclefs $2"
echo $command
command="echo $password | $command"
response=$(eval $command)
rc=$(echo $?)
if [ $rc == 0 ]
then
echo "command passed"
else
echo "command failed"
exit $rc
fi
state=$(echo "$response" | grep -w SystemStatus | awk -F': ' '{print $2}')
echo "system status is '$state'"
echo ""
if [ $state != "NORMAL" ]
then
exit $rc
fi
# check source lun status
command="./fscli lun -list -details -lun $3 -u $1 -oraclefs $2"
echo $command
command="echo $password | $command"
response=$(eval $command)
rc=$(echo $?)
if [ $rc == 0 ]
then
echo "command passed"
else
echo "command failed"
exit $rc
fi
state=$(echo "$response" | grep -w Status | awk -F': ' '{print $2}')
echo "source lun status is '$state'"
echo ""
if [ $state != "ONLINE" ]
then
exit $rc
fi
# check backup server status
command="./fscli san_host -list -details -sanhost $4 -u $1 -oraclefs $2"
echo $command
command="echo $password | $command"
response=$(eval $command)
rc=$(echo $?)
if [ $rc == 0 ]
then
echo "command passed"
else
echo "command failed"
exit $rc
fi
state=$(echo "$response" | grep -w ManagementState | awk -F': ' '{print $2}')
echo "backup server status is '$state'"
echo ""
if [ $state != "AVAILABLE" ]
then
exit $rc
fi
# get next available lun number
command="./fscli hostmap -list -availablelunnumbers -host $4 -u $1 -oraclefs $2"
echo $command
command="echo $password | $command"
response=$(eval $command)
rc=$(echo $?)
if [ $rc == 0 ]
then
echo "command passed"
else
echo "command failed"
exit $rc
fi
lunnumber=$(echo "$response" | grep -w LunNumber | head -n1 | awk -F': ' '{print $2}')
echo "next available lun number is '$lunnumber'"
echo ""
# add clone
command="./fscli clone_lun -add -name $5 -source $3 -hostmap $4 -lunnumber $lunnumber -u $1 -oraclefs $2"
echo $command
command="echo $password | $command"
response=$(eval $command)
rc=$(echo $?)
if [ $rc == 0 ]
then
echo "command passed"
else
echo "command failed"
exit $rc
fi
echo ""
# check clone status
command="./fscli clone_lun -list -details -clonelun /$5 -u $1 -oraclefs $2"
echo $command
command="echo $password | $command"
response=$(eval $command)
rc=$(echo $?)
if [ $rc == 0 ]
then
echo "command passed"
else
echo "command failed"
exit $rc
fi
state=$(echo "$response" | grep -w Status | awk -F': ' '{print $2}')
echo "clone lun status is '$state'"
echo ""
if [ $state != "ONLINE" ]
then
exit $rc
fi
# call backup application
echo "call backup application"
echo "backup complete"
echo ""
# delete clone
command="./fscli clone_lun -delete -clonelun /$5 -suppresswarnings -u $1 -oraclefs $2"
echo $command
command="echo $password | $command"
response=$(eval $command)
rc=$(echo $?)
if [ $rc == 0 ]
then
echo "command passed"
else
echo "command failed"
exit $rc
fi
echo ""
echo ""
|
#! /usr/bin/env bash
# example script using fscli credentials to add clone,
# call backup, and delete clone
# verify command line arguments
if [ $# -ne 3 ]; then
echo "Usage: ./$(basename $0) <source-lun-fqn> <backup-server-fqn> <clone-lun-name>"
exit 1
fi
# prompt for password
read -s -p "Password: " password
echo ""
echo ""
# check overall system status
command="./fscli system -list -status"
echo $command
command="echo $password | $command"
response=$(eval $command)
rc=$(echo $?)
if [ $rc == 0 ]
then
echo "command passed"
else
echo "command failed"
exit $rc
fi
state=$(echo "$response" | grep -w SystemStatus | awk -F': ' '{print $2}')
echo "system status is '$state'"
echo ""
if [ $state != "NORMAL" ]
then
exit $rc
fi
# check source lun status
command="./fscli lun -list -details -lun $1"
echo $command
command="echo $password | $command"
response=$(eval $command)
rc=$(echo $?)
if [ $rc == 0 ]
then
echo "command passed"
else
echo "command failed"
exit $rc
fi
state=$(echo "$response" | grep -w Status | awk -F': ' '{print $2}')
echo "source lun status is '$state'"
echo ""
if [ $state != "ONLINE" ]
then
exit $rc
fi
# check backup server status
command="./fscli san_host -list -details -sanhost $2"
echo $command
command="echo $password | $command"
response=$(eval $command)
rc=$(echo $?)
if [ $rc == 0 ]
then
echo "command passed"
else
echo "command failed"
exit $rc
fi
state=$(echo "$response" | grep -w ManagementState | awk -F': ' '{print $2}')
echo "backup server status is '$state'"
echo ""
if [ $state != "AVAILABLE" ]
then
exit $rc
fi
# get next available lun number
command="./fscli hostmap -list -availablelunnumbers -host $2"
echo $command
command="echo $password | $command"
response=$(eval $command)
rc=$(echo $?)
if [ $rc == 0 ]
then
echo "command passed"
else
echo "command failed"
exit $rc
fi
lunnumber=$(echo "$response" | grep -w LunNumber | head -n1 | awk -F': ' '{print $2}')
echo "next available lun number is '$lunnumber'"
echo ""
# add clone
command="./fscli clone_lun -add -name $3 -source $1 -hostmap $2 -lunnumber $lunnumber"
echo $command
command="echo $password | $command"
response=$(eval $command)
rc=$(echo $?)
if [ $rc == 0 ]
then
echo "command passed"
else
echo "command failed"
exit $rc
fi
echo ""
# check clone status
command="./fscli clone_lun -list -details -clonelun /$3"
echo $command
command="echo $password | $command"
response=$(eval $command)
rc=$(echo $?)
if [ $rc == 0 ]
then
echo "command passed"
else
echo "command failed"
exit $rc
fi
state=$(echo "$response" | grep -w Status | awk -F': ' '{print $2}')
echo "clone lun status is '$state'"
echo ""
if [ $state != "ONLINE" ]
then
exit $rc
fi
# call backup application
echo "call backup application"
echo "backup complete"
echo ""
# delete clone
command="./fscli clone_lun -delete -clonelun /$3 -suppresswarnings"
echo $command
command="echo $password | $command"
response=$(eval $command)
rc=$(echo $?)
if [ $rc == 0 ]
then
echo "command passed"
else
echo "command failed"
exit $rc
fi
echo ""
echo ""
|