•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,575 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,596 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 845 | Replies: 3
![]() |
•
•
Join Date: Oct 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Please pardon the simplicity of this question, I kind of got thrown into these responsibilities at the last minute without training.
I
I need to move a file called status10.dat to a different directory using korn scripting.
[code = korn]
cp status10.dat* /cerner/d_p19/ccluserdir
[/code]
I only want to do this if the file is equal to today's date. Is it possible to check before moving the file?
Thanks in advance
I
I need to move a file called status10.dat to a different directory using korn scripting.
[code = korn]
cp status10.dat* /cerner/d_p19/ccluserdir
[/code]
I only want to do this if the file is equal to today's date. Is it possible to check before moving the file?
Thanks in advance
•
•
Join Date: Oct 2007
Posts: 306
Reputation:
Rep Power: 2
Solved Threads: 29
Hi There,
That shouldn't be a problem at all.
Depending on what you want to do you can use find to get all files created within the last 24 hours (assuming /home as your current directory):
for x in `find /home -mtime 0`
do
mv $x /cernet/d_p19/ccluserdir/.
done
you can also use the -exec option of find to do the mv for you so you'd just have a one-line find script.
Hope this helps
, Mike
That shouldn't be a problem at all.
Depending on what you want to do you can use find to get all files created within the last 24 hours (assuming /home as your current directory):
for x in `find /home -mtime 0`
do
mv $x /cernet/d_p19/ccluserdir/.
done
you can also use the -exec option of find to do the mv for you so you'd just have a one-line find script.
Hope this helps

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
•
•
Join Date: Oct 2007
Posts: 306
Reputation:
Rep Power: 2
Solved Threads: 29
Hey, I just noticed that I misread your question - you need stuff from "today" and not the last 24 hours -- sorry - maybe that other info will be useful for another project.
If you want to only delete files from today, I think the simplest way to do it - to avoid the possible issues with spacing and/or tabbing would be to write a script that took a date argument in the following format:
./yourscript "Oct 3"
or
./yourscript "Oct 24"
Note that in the "Oct 3" there are two spaces separating the month and date and that "Oct 24" only has one space separating - this is to accommodate the behavious of "ls -l" -- at least, on solaris.
yourscript would be (assuming we're running it from the directory your files are in)
#!/bin/ksh
today=$1
for x in `ls -ld *`
do
filename=`echo $x|awk '{print $1}'`
result=`echo $x |grep $today >/dev/null 2>&1`
if [ $? -eq 0 ]
then
mv $filename /cernet/d_p19/ccluserdir/.
fi
done
I tend to write the short-stuff like I think. There's probably an easier way to do it
Thanks,
, Mike
If you want to only delete files from today, I think the simplest way to do it - to avoid the possible issues with spacing and/or tabbing would be to write a script that took a date argument in the following format:
./yourscript "Oct 3"
or
./yourscript "Oct 24"
Note that in the "Oct 3" there are two spaces separating the month and date and that "Oct 24" only has one space separating - this is to accommodate the behavious of "ls -l" -- at least, on solaris.
yourscript would be (assuming we're running it from the directory your files are in)
#!/bin/ksh
today=$1
for x in `ls -ld *`
do
filename=`echo $x|awk '{print $1}'`
result=`echo $x |grep $today >/dev/null 2>&1`
if [ $? -eq 0 ]
then
mv $filename /cernet/d_p19/ccluserdir/.
fi
done
I tend to write the short-stuff like I think. There's probably an easier way to do it

Thanks,
, Mike
Last edited by eggi : Oct 29th, 2007 at 5:14 pm. Reason: misspelling again - no more edits coming - thx :)
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- How to print to file (Perl)
- [Question] exe to source file (C++)
- Excel Macro Save as with date in file name (Visual Basic 4 / 5 / 6)
- Newbie Question - How to generate a link (PHP)
- Hosts file question about Gorilla's explanation (Viruses, Spyware and other Nasties)
- How to Add date to file Name (Windows NT / 2000 / XP / 2003)
- inputing system("date /t") and system("time /t") into a file (C++)
- EASY question? checking for line feed (return) in a html file with C++ (C++)
Other Threads in the Shell Scripting Forum
- Previous Thread: call the constructor of java class from script
- Next Thread: su - postgres within shell script


Linear Mode