Home > Enterprise >  Modify a bash script so that the network port used to connect is specified by a command-line argumen
Modify a bash script so that the network port used to connect is specified by a command-line argumen

Time:05-02

Modify smtp.sh so that the network port used to connect is specified by a command-line argument (e.g., ./smtp.sh 192.168.0.15 25).

#!/bin/bash -
#
# smtp.sh
#
# Connect to a SMTP server
#
# Usage:
# smtp.sh <host>

exec 3<>/dev/tcp/"$1"/25
echo -e 'quit\r\n' >&3
cat <&3

How to modify the code? Cause I'm really new to this. I have tried exec 3<> /dev/tcp/host/port, but I'm not sure of the command

CodePudding user response:

this should work:

exec 3<>/dev/tcp/"$1"/"$2"

now execute your script with two arguments

ex:

user@server:~$ ./yourScrip.sh Hostname 25
  • Related