将public ip写入txt自动上传到FTP? (linux)
Write public ip to txt and upload to FTP automatically? (linux)
所以我正在寻找一种方法来将创建的各种文本文件上传到 ftp
它需要每隔 4 小时发生一次
- 检查ip
- 将ip写入文档或其他任何内容
- 使用特定的 IP 地址、用户名和密码将其上传到 FTP 服务器
我正在使用 Linux 所以 sh 脚本就可以了
如果你能解释一下发生了什么那就太好了
-(尽管使用 Linux Mint 和 Fedora 21 已经 5 年了,但我仍在学习很多东西)
到目前为止我有
dig +short myip.opendns.com @resolver1.opendns.com
这得到了我的 public ip,接下来是将其写入文档并上传到我不知道的 ftp 服务器。
最后一点补充说明,我正在寻找这个 运行 每 4 小时一次。
快速而肮脏的第一刺:
#!/bin/bash
# ftpmyip.sh
HOST=ftpserver
USER=userid
PASSWD=userpw
# write my ip address to file my_ip.txt
dig +short myip.opendns.com @resolver1.opendns.com > my_ip.txt
# ftp file to the ftp server
ftp -n $HOST <<SCRIPT
user $USER $PASSWD
binary
put my_ip.txt
quit
SCRIPT
现在,使用 crontab -e 将其全部放入 cron 作业中;行应该说:
0 */4 * * * /home/enviousdata/ftpmyip.sh
所以我正在寻找一种方法来将创建的各种文本文件上传到 ftp
它需要每隔 4 小时发生一次
- 检查ip
- 将ip写入文档或其他任何内容
- 使用特定的 IP 地址、用户名和密码将其上传到 FTP 服务器
我正在使用 Linux 所以 sh 脚本就可以了
如果你能解释一下发生了什么那就太好了 -(尽管使用 Linux Mint 和 Fedora 21 已经 5 年了,但我仍在学习很多东西)
到目前为止我有
dig +short myip.opendns.com @resolver1.opendns.com
这得到了我的 public ip,接下来是将其写入文档并上传到我不知道的 ftp 服务器。
最后一点补充说明,我正在寻找这个 运行 每 4 小时一次。
快速而肮脏的第一刺:
#!/bin/bash
# ftpmyip.sh
HOST=ftpserver
USER=userid
PASSWD=userpw
# write my ip address to file my_ip.txt
dig +short myip.opendns.com @resolver1.opendns.com > my_ip.txt
# ftp file to the ftp server
ftp -n $HOST <<SCRIPT
user $USER $PASSWD
binary
put my_ip.txt
quit
SCRIPT
现在,使用 crontab -e 将其全部放入 cron 作业中;行应该说:
0 */4 * * * /home/enviousdata/ftpmyip.sh