LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-13-2012, 02:48 PM   #1
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
more BASH issues.


still trying to clean out some of the old data...

Code:
[101635 Live_server_rx30@rx30 ~]$ sh -xvv MOVE
#!/bin/bash
license=`showlic | grep LICENSE | awk '{print $6}'`
showlic | grep LICENSE | awk '{print $6}'
++ showlic
++ grep LICENSE
++ awk '{print $6}'
+ license=101635
DIR=/tmp/DEA-${license}
+ DIR=/tmp/DEA-101635


[ ! -d "${DIR}" ] && mkdir -p ${DIR}
+ '[' '!' -d /tmp/DEA-101635 ']'
[ -f `20[0-9]*.dat` ] && find 20[0-9]*.dat -mtime +15 -exec mv '{}' ${DIR} \;
20[0-9]*.dat
++ 20111122.dat 20111123.dat 20111202.dat 20111212.dat 20111222.dat 20111230.dat 20120109.dat 20120119.dat 20120126.dat 20120202.dat 20120213.dat 20120228.dat 20120306.dat 20120313.dat 20120315.dat 20120330.dat 20120410.dat 20120430.dat 20120510.dat 20120530.dat 20120613.dat 20120620.dat 20120628.dat 20120712.dat 20120725.dat 20120813.dat 20120822.dat 20120828.dat 20120830.dat 20120905.dat
./20111122.dat: line 1: TH*4.1*1122111051*01**20111122*105110*P**\IS*8634523040*CENTRAL: command not found
+ '[' -f ']'
+ find 20111122.dat 20111123.dat 20111202.dat 20111212.dat 20111222.dat 20111230.dat 20120109.dat 20120119.dat 20120126.dat 20120202.dat 20120213.dat 20120228.dat 20120306.dat 20120313.dat 20120315.dat 20120330.dat 20120410.dat 20120430.dat 20120510.dat 20120530.dat 20120613.dat 20120620.dat 20120628.dat 20120712.dat 20120725.dat 20120813.dat 20120822.dat 20120828.dat 20120830.dat 20120905.dat -mtime +15 -exec mv '{}' /tmp/DEA-101635 ';'
exit
+ exit
[101635 Live_server_rx30@rx30 ~]$ cat MOVE
#!/bin/bash
license=`showlic | grep LICENSE | awk '{print $6}'`
DIR=/tmp/DEA-${license}


[ ! -d "${DIR}" ] && mkdir -p ${DIR}
[ -f `20[0-9]*.dat` ] && find 20[0-9]*.dat -mtime +15 -exec mv '{}' ${DIR} \;
exit
[101635 Live_server_rx30@rx30 ~]$ mv /tmp/DEA-101635/*.dat .
[101635 Live_server_rx30@rx30 ~]$ MOVE
./20111122.dat: line 1: TH*4.1*1122111051*01**20111122*105110*P**\IS*8634523040*CENTRAL: command not found
why am i getting those errors?

Code:
-rwxr-xr-x  1 rx30 group     81949 Nov 22  2011 20111122.dat
-rwxr-xr-x  1 rx30 group     79744 Nov 23  2011 20111123.dat
-rwxr-xr-x  1 rx30 group       839 Dec  2  2011 20111202.dat
-rwxr-xr-x  1 rx30 group      1528 Dec 12  2011 20111212.dat
-rwxr-xr-x  1 rx30 group      3376 Dec 22  2011 20111222.dat
-rwxr-xr-x  1 rx30 group      3476 Dec 30  2011 20111230.dat
-rwxr-xr-x  1 rx30 group       840 Jan  9  2012 20120109.dat
-rwxr-xr-x  1 rx30 group      1520 Jan 19  2012 20120119.dat
-rwxr-xr-x  1 rx30 group      2586 Jan 26  2012 20120126.dat
-rwxr-xr-x  1 rx30 group      2868 Feb  2  2012 20120202.dat
the files are there and look as above. the list is WAY to LONG to print em all. point is they are older then 15 days old, except for 1 as it is dated 9/5/2012 would that one give the error?

i have not seen a find -mtime provide that type of error before.

if i understand what i have setup, the
Code:
[ -f `20[0-9]*.dat` ]
is just a check to see if those types of files are in the directory and are regular files.

the && says if the before is true, then perform the latter.

Code:
find 20[0-9]*.dat -mtime +15 -exec mv '{}' ${DIR} \;
that is a rather straight forward simple command. find all of those types of files that are older then 15 days and move them to the proper directory...

What am I missing?
 
Old 09-13-2012, 04:22 PM   #2
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Original Poster
Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
nm, ended up with the following code:

Code:
#!/bin/bash

license=`showlic | grep LICENSE | awk '{print $6}'`
DIR=/tmp/DEA-${license}
VAR=`cat deafile.out`

[ ! -d "${DIR}" ] && mkdir -p ${DIR}

if [ -f deaopts.fil ]
then
        rm -rf deaopts.fil
fi

if [ -f PMP*.dat ]
then
        find PMP*.dat -mtime +15 -exec mv '{}' ${DIR} \;
fi

if [ -f 20[0-9]*.dat ]
then
        find 20[0-9]*.dat -mtime +15 -exec mv '{}' ${DIR} \;
fi

if [ -f 20[0-9]*.txt ]
then
        find 20[0-9]*.txt -mtime +15 -exec mv '{}' ${DIR} \;
fi

filemove ()

{
for f in deaopts.*.orig
do
        newf=$(echo $f | tr '[:lower:]' '[:upper:]')
        mv "$f" "$newf"
        #mv "$f" "${f^^}"
done
}


deaclean()

{

for f in deaopts.*
do
        LINE=`head -n 1 $f`
        find ${LINE:3:3}*.* -mtime +15 -exec mv '{}' ${DIR} \;

        find ${VAR} -mtime +15 -exec mv '{}' \;
done

}


filemove

deaclean

exit
cleaned, tested, and finished.
 
Old 09-13-2012, 04:38 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
With the major difference between those two incantations being that
the original file-test's parameters was wrapped in back-ticks, and the final
versions aren't.

[ -f `20[0-9]*dat` ] get's expanded, the first match inside the `` gets
interpreted by the subshell as a command (which it can't find, and it tells
you about it).



Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script issues -- halp! danowar Programming 14 02-09-2012 03:37 PM
CURL issues in bash iniuria Programming 1 03-08-2010 03:39 AM
file copying issues with bash Furlinastis Programming 3 05-03-2006 01:32 AM
issues programming a script in BASH gravesb Linux - Software 1 07-07-2005 01:03 AM
Bash Issues Crashed_Again Linux - General 3 02-23-2004 01:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration