LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell script (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-4175530088/)

kuriyo 01-05-2015 09:36 AM

Shell script
 
could you please give a help on writing a shell script that will move from folder1 to folder2 on an houlry basis and re_name the folders into folder2 as "%Y%m%d%hh24"`

TenTenths 01-05-2015 09:41 AM

What have you written so far?

TB0ne 01-05-2015 10:05 AM

Quote:

Originally Posted by kuriyo (Post 5295656)
could you please give a help on writing a shell script that will move from folder1 to folder2 on an houlry basis and re_name the folders into folder2 as "%Y%m%d%hh24"`

Please see the "LQ Question Guidelines" link in my posting signature.

We will be happy to HELP you with a script, but we are not going to write it for you. There are MANY THOUSANDS of bash scripting tutorials you can find with a brief Google search. If you post what you have written yourself and tell us what you're stuck on/confused about, we will be happy to assist.

kuriyo 01-05-2015 10:14 AM

#/bin/sh

cd
. ./.profile

cd /baksett/media/orgdata/backup

today_hour=`date +"%Y%m%d%k"`

mkdir $today_hour

mv b*.dat /baksett/media/orgdata/backup/$today_hour

cd /baksett/media/orgdata/backup/$today_hour

ftp -ni 10.20.0.18 <<EOF
user lio test
binary
mput b*.dat
quit
EOF

>>>i got nothing for now

TenTenths 01-05-2015 10:17 AM

Quote:

Originally Posted by kuriyo (Post 5295675)
Code:

#/bin/sh

cd
. ./.profile

cd /baksett/media/orgdata/backup

today_hour=`date +"%Y%m%d%k"`

mkdir $today_hour

mv b*.dat /baksett/media/orgdata/backup/$today_hour

cd /baksett/media/orgdata/backup/$today_hour

ftp -ni 10.20.0.18 <<EOF
user lio test
binary
mput b*.dat
quit
EOF

>>>i got nothing for now

Nothing where? In the newly created folder or at the ftp side?


Try adding set -x as the second line of your script and then run it, that'll let you see each line as it's being processed, you may get a clue.

kuriyo 01-05-2015 11:26 AM

in the newly created folder

unSpawn 01-05-2015 05:57 PM

Note using "%k" almost never makes sense (while "%H" does) and since you 'mv' files instead of using 'cp' there may be nothing left to move?..
To see what a script and subsequent commands actually do execute in verbose mode:

Code:

#/bin/bash -vx
TIMESTAMP=$(/bin/date +"%Y%m%d_%H")
cd
. ~/.profile
cd /baksett/media/orgdata/backup
mkdir "${TIMESTAMP}"
/bin/mv -v b*.dat "/baksett/media/orgdata/backup/${TIMESTAMP}"
cd "/baksett/media/orgdata/backup/${TIMESTAMP}"
ftp verbose -ni 10.20.0.18 <<EOF
user lio test
binary
mput b*.dat
quit
EOF

exit 0

and check the output. If unsure post everything [code]and between BB tags[/code].

kuriyo 01-06-2015 07:46 AM

i tried to put event the tags and i still don't get an ouput
Thx

unSpawn 01-06-2015 12:30 PM

We can't read minds nor look at your terminal window: post complete output and between BB code tags.

igadoter 01-06-2015 09:08 PM

I would try ftp command on local host. For testing
Code:

ftp ni localhost << EOF ..


All times are GMT -5. The time now is 04:04 PM.