首页 > 技术文章 > shell 交互并调用perl

anxbai 2021-08-20 11:16 原文

1 shell 交互 :

echo -n "Enter The name :"
read name
2 调用 perl 脚本:
/usr/bin/sudo /opt/callhome.pl

for instance :

function input_name(){
    echo -n "Enter The name :"
    read name
    check_name $name
}

function check_name(){
    name=$1
    if [ $1x == "x" ]; then 
    	echo "The name cannot be empty!"
    	input_name
    elif [[ "$1" =~ ^[a-zA-Z]+[a-zA-Z0-9_.]* ]] && [ ${#snmpname} -le 32 ]; then
        return
    else 
    	echo " Username should not be more than 32 characters. Spaces and Special characters are not allowed. Allowed characters are '.','-','_' >"
    	input_name
    fi
}
if [ $1 == "AuthPriv" ]; then
    input_snmp_name
    echo -e
    /usr/bin/sudo /opt/callhome.pl 

结果 :

:/> bash  /opt/security.sh AuthPriv

Enter The name of snmp :
 The snmp name cannot be empty!
Enter The name of snmp :@#$$
 Username should not be more than 32 characters. Spaces and Special characters are not allowed. Allowed characters are '.','-','_' >
Enter The name of snmp :admin

推荐阅读