how to use data variable in mkdir in a linux server with FTP?

假装没事ソ 提交于 2019-12-23 04:03:06

问题


I need to create a folder in my FTP server, whose name is "YYYY-MM-DD"; I have this variable:

slideshow=$(date +"%Y-%m-%d")

but I can not use it in FTP with mkdir, since it's a shell variable.

I've also tried with echo, and there it works (I have "mkdir 2015-05-25" in a sh file), but if I have a series of commands that have to be run, just the first ftp -n ftp.xxxx.it. is run, the rest (user, password) isn't.

I hope you could help me,

Thanks


回答1:


this script seems to be like this topic enter link description here

but you can do it easily by mkdir a new directory on your pc then upload it to your server by this simple script

#!/bin/bash

Your Server credentials

ftp_server='******' 
ftp_username='******' 
ftp_password='******'  

New folder with date in year with month and day

slideshow="`date +'%Y-%m-%d'`" 
new_folder=`mkdir $slideshow` 

Access Your Server via ftp then authenticate to your server

ftp -n $ftp_server <<END_SCRIPT 
quote USER $ftp_username  
quote PASS $ftp_password 

Upload your new created folder

put $new_folder 

then quit

quit  
END_SCRIPT

full script

#!/bin/bash

ftp_server='********'
ftp_username='********'
ftp_password='********'
slideshow="`date +'%Y-%m-%d'`"
new_folder=`mkdir $slideshow`

ftp -n $ftp_server <<END_SCRIPT
quote USER $ftp_username
quote PASS $ftp_password
put $new_folder
quit
END_SCRIPT


来源:https://stackoverflow.com/questions/30436493/how-to-use-data-variable-in-mkdir-in-a-linux-server-with-ftp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!