LinuxQuestions.org
Help answer threads with 0 replies.
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 04-24-2009, 03:09 AM   #1
ananthi_ku
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Rep: Reputation: 0
Getting all the files modified today & store the names in a variable as , separated


Hi all,

I am very new to linux. I have a question. I have a folder. I want to find the list of files that are modified today and store all those file names in a variable as comma separated values. I thought of using
"find . -mtime 0" command to find the list of files modified today. Also to get those values of file name stored in a variable, I thought of using
"find . -mtime 0 | awk '{print $1}'" command. But 1 value is hard coded in that. I need to know how many outputs coming out of "find . -mtime 0" command so that i can dynamically vary my print statement in awk.

Any help on this.

Thanks in advance.

Thanks,
Ananthi.U
 
Old 04-24-2009, 03:14 AM   #2
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Couldn't you just use something like

find . -mtime 0 -printf "%p, "

Edit - you may want to use the -daystart option if you really want the files from today ratehr than last 24 hours.

find ./ -daystart -mtime 0 -printf "%p, "

Last edited by billymayday; 04-24-2009 at 03:18 AM.
 
Old 04-24-2009, 03:58 AM   #3
Dudydoo
Member
 
Registered: Sep 2003
Location: UK
Distribution: I use 'em all ;-)
Posts: 275

Rep: Reputation: 38
MYARRAY=( `find . -mtime 0` )

for file in ${MYARRAY[@]
do
echo $file
done
 
Old 04-27-2009, 06:01 AM   #4
ananthi_ku
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Hi all,,

Thanks for ur replies.

I got that issue solved with the help of outfilename=$(find . -type f -mtime 0 | tr '\n' ',');

I am facing another issue with this find.....

Here is my program



#!/bin/sh
# Environmental set up
envSet="true";

# Initialize error code
error_code="false";

if [ "$envSet" = "$2" ]
then
# Set batch environment
. $1/jobs/setBatchEnv.sh $1
fi

echo "file name ---------"$filename
echo "BATCH_HOME ---------"$BATCH_HOME
echo "3 ---------"$3

#Frame the output file name
if [ "$filename" != "" ]
then
echo "Inside IF"
#if ZipReports.sh executed, then the filename of the zip will be taken from that
outfilename = $filename;
else
echo "Inside ELSE"
#if ZipReports.sh not executed, then the filename will be the list of files that are last modified today
cd $BATCH_HOME/data/output/$3
pwd
outfilename=$(find . -type f -mtime 0 | tr '\n' ',');
fi

echo "outifle-------"$outfilename

# Call the EmailReportsBatch.java program
$JAVA_HOME/java -Xmx1024m -Djava.awt.headless=true \
-DPROPERTIES_PATH=$BATCH_HOME/properties \
-DREPORT_TYPE=$3 \
-DOUTPUT_PATH=$BATCH_HOME/data/output/$3/ \
-DOUTPUT_FILE=$outfilename \
batch.EmailReportsBatch > $LOG_DIR/EmailReportsBatch.log

# Check if java command fails
if test ! $? -eq 0
then
error_code="true";
fi




When i execute this pgm i am getting the outfilename value correctly. But when it is invoked from main shell(this main shell will generate the reports and then call this shell to mail all the generated reports) this outfilename is giving me one value less than what it is supposed to give. That is if 3 files are modified today, it is giving only 2 file names. Any suggestion why this is happening? But when BATCH_HOME, $3 values are echoed they show the same results...
 
  


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
Where does KDE store virtual desktop names? grunt547 Linux - Desktop 11 04-03-2009 05:51 PM
Linux store names and ideas. maxie General 19 03-21-2006 06:48 AM
monitoring directory to get the modified file names appas Programming 1 09-06-2004 05:56 AM
Save last modified to a variable twantrd Programming 2 03-31-2004 04:57 AM
Store PATH variable permanently Skute Linux - Software 8 01-15-2004 05:05 PM


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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration