Shell Script not showing accurate Time Stamp and Size
Hey guys - I have made this script and for some reason, I dont see time stamp as "Month-Day-YYYY Hours-Mins" - all i see is Month and Day.
Also, my file size is approximated. For example, if the size is 19,606KB - the script shows as 20M. Is there a way to see the exact file size?
How do i accomplish the above tasks?
Code:
#!/bin/bash
# setting default path
PATH="/usr/bin:/bin:/usr/sbin"
NOW=$(date +"%Y-%m-%d")
LOG_FILE=/tmp/myemail.txt
FILE_NOT_FOUND="/tmp/missingfiles.txt"
CURRENT_FILE="/tmp/currentfiles.txt"
OLD_FILE="/tmp/oldfiles.txt"
# make sure we create a new copy of these files
rm -f $LOG_FILE $FILE_NOT_FOUND $CURRENT_FILE $OLD_FILE
# List the directories and files to process.
DIR="dir1 dir2"
FILE="file 1 file 2"
#############################
# Define functions
#############################
function checkStat
{
# make sure stat command is installed
which stat > /dev/null 2>&1
if [ $? -eq 1 ]; then
echo "stat command not found!"
exit 2
fi
}
function processFile
{
if [ -s ${1} ]; then
VAR="$(stat -c %y ${1})"
VAR2="${VAR:0:10}"
FILE_TIME=$(ls -l $1| cut -d" " -f6,7)
FILE_SIZE=$(du -sh $1 | cut -f1)
if [ $NOW == $VAR2 ]; then
echo "Current File Found: ${1} $FILE_TIME - SIZE $FILE_SIZE" | tee -a ${CURRENT_FILE}
else
erroremail=1
echo "Old File Found: ${1} $FILE_TIME SIZE - $FILE_SIZE" | tee -a ${OLD_FILE}
fi
else
erroremail=1
echo "File Not Found: ${1}" | tee -a ${FILE_NOT_FOUND}
fi
}
#############################
# Main
#############################
# Verify the stat command exists
checkStat
# Create log file
touch ${LOG_FILE}
# Process the files
for d in ${DIR[@]}; do
for f in ${FILE[@]}; do
processFile "${d}/${f}"
done
done
#############
#Email
#############
if [ $erroremail -eq 1 ] ; then
SUBJECT="ERROR: File Problem"
else
SUBJECT="OK: File Current"
fi
# lets populate the sendmail files
echo "To:someone@nowhere.com" >>$LOG_FILE
echo "Subject:$SUBJECT" >> $LOG_FILE
# Append list of current files to Email body
# Make sure we display error message only once
error_display=false
# Append list of old files to Email body
if [ -s $OLD_FILE ]; then
echo "*********************ERROR MESSAGES********************" >> $LOG_FILE
error_display=true
echo "List of old files" >> $LOG_FILE
cat $OLD_FILE >> $LOG_FILE
fi
# blank lines between two data
echo >> $LOG_FILE
echo >> $LOG_FILE
# Append list of missing files to Email body
if [ -s $FILE_NOT_FOUND ]; then
if [ "$error_display" = "false" ]; then
echo "*********************ERROR MESSAGES********************" >> $LOG_FILE
fi
echo "List of missing files" >> $LOG_FILE
cat $FILE_NOT_FOUND >> $LOG_FILE
fi
# blank lines between two data
echo >> $LOG_FILE
echo >> $LOG_FILE
if [ -s $CURRENT_FILE ]; then
echo "****************GOOD MESSAGES*************************" >> $LOG_FILE
echo "List of current files" >> $LOG_FILE
cat $CURRENT_FILE >> $LOG_FILE
fi
# send an email using /sbin/sendmail
sendmail -t < $LOG_FILE
if [ $? -eq 0 ]; then
echo "Sent mail successfully"
else
echo "Error sending mail"
fi
# cleanup files
rm -f $LOG_FILE $FILE_NOT_FOUND $CURRENT_FILE $OLD_FILE
Hi,
I need to write a script,which behaves like this,
Given the folder name, it should list the files with today's timestamp.
Please direct me on this.
Thanks. (2 Replies)
Hi,
while running the perl script i am getting this error message ,
Day '' out of range 1..31 at rsty.sh line 44
what do iam missing in the script, any suggestion
#!/usr/bin/perl
use Time::Local;
my $wday = $ARGV;
my $month = $ARGV;
# convert the month shortname into 0-11 number
if... (4 Replies)
I have searched several thread and not found my solution, so I am posting a new qustion.
I have a very simple script on an AIX server that FTPs 2 files to a MS FTP server. These 2 files are created on the AIX server every hour, with a static name.
I need to FTP the files to the MS server, but... (1 Reply)
I need some help recovering from a "slight" screwup. We just moved 3 TB of data from one RAID Array to another. Low lever archive files. This was done with a regular cp (for some reason) and now we have lost all the timestamps on the files, and we urgently need to get the timestamps back on these... (7 Replies)
Hi all,
Does anybody know how to build a cycle accurate simulator? I've looked at QEMU and SESC simulator, but they are only cycle accurate for the CPU part. I'm looking for a simulator which can estimate the performance including CPU and I/O. For example, when I configure the simulator by SSD... (2 Replies)
Hi,
I need to run a script file which uses a file and that file is modified as and when some alarms generated, it is not based on any fixed time period.. it may be modified even once in a minute for some time and once in 30 min or once in 20 min. Hence i need to watch for the timestamp change of... (3 Replies)
How do I store the time stamps of each command executed for C shell users?
However, I am able to set this for Bash users with this command:
export HISTTIMEFORMAT="%F %T "
This is how a typical .cshrc look like for a Cshell user:
# more .cshrc
# necessary to get hostname... (3 Replies)
Help with Perl script :
I have a web.xml file with a line
<display-name>some_text_here</display-name>
Need to append the current date and time stamp to the string and save the XML file
Something like
<display-name>some_text_here._01_23_2014_03_56_33</display-name>
-->Finally want... (5 Replies)
I am developing one script which will take log file name, output file name, date, hour and minute as an argument and based on these inputs, the script will scan and capture all the error(s) that have been triggered from a given time. Example: script should capture all the error after 13:50 on Jan... (2 Replies)
I am trying to configure dump devices on my AIX server. Running 7100-03-04-1441. My dump device needs to be about 2GB in size. My PP Size is 1024MB, so I create the device with 2 PPs. When I run lslv on the dump device, it shows the 2 PPs, and a PP Size of 1024 megabytes. However, a dumpcheck... (4 Replies)
Discussion started by: paqman
4 Replies
LEARN ABOUT PHP
echo
ECHO(3) 1 ECHO(3)echo - Output one or more stringsSYNOPSIS
void echo (string $arg1, [string $...])
DESCRIPTION
Outputs all parameters.
echo is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo (unlike some other
language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want
to pass more than one parameter to echo, the parameters must not be enclosed within parentheses.
echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syn-
tax only works with the short_open_tag configuration setting enabled.
I have <?=$foo?> foo.
PARAMETERS
o $arg1
- The parameter to output.
o $...
-
RETURN VALUES
No value is returned.
EXAMPLES
Example #1
echo examples
<?php
echo "Hello World";
echo "This spans
multiple lines. The newlines will be
output as well";
echo "This spans
multiple lines. The newlines will be
output as well.";
echo "Escaping characters is done "Like this".";
// You can use variables inside of an echo statement
$foo = "foobar";
$bar = "barbaz";
echo "foo is $foo"; // foo is foobar
// You can also use arrays
$baz = array("value" => "foo");
echo "this is {$baz['value']} !"; // this is foo !
// Using single quotes will print the variable name, not the value
echo 'foo is $foo'; // foo is $foo
// If you are not using any other characters, you can just echo variables
echo $foo; // foobar
echo $foo,$bar; // foobarbarbaz
// Some people prefer passing multiple parameters to echo over concatenation.
echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10);
echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "
";
echo <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon. no extra whitespace!
END;
// Because echo does not behave like a function, the following code is invalid.
($some_var) ? echo 'true' : echo 'false';
// However, the following examples will work:
($some_var) ? print 'true' : print 'false'; // print is also a construct, but
// it behaves like a function, so
// it may be used in this context.
echo $some_var ? 'true': 'false'; // changing the statement around
?>
NOTES
Note
Because this is a language construct and not a function, it cannot be called using variable functions.
SEE ALSO print(3), printf(3), flush(3), Heredoc syntax.
PHP Documentation Group ECHO(3)