'Modify a bash script so that the network port used to connect is specified by a command-line argument
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
Solution 1:[1]
this should work:
exec 3<>/dev/tcp/"$1"/"$2"
now execute your script with two arguments
ex:
user@server:~$ ./yourScrip.sh Hostname 25
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | S. Mondal |
