10-04-2011
Ok, here it is:
The script is not finished yet. The goal of the script is to select all events from ical by screening all the .ics files for events in the next 24 hours.
Quote:
#!/bin/bash
# Create temporary directory
mkdir -p ~/tmp/iCal_GeekLet
tmpdir=~/tmp/iCal_GeekLet
rm -f ${tmpdir}/1_epoch.txt
rm -f ${tmpdir}/2_time.txt
rm -f ${tmpdir}/3_event.txt
rm -f ${tmpdir}/4_location.txt
#Save current time as epoch
Epoch_current=`date +%s`
#Add 24 hours
Epoch_24=$[${Epoch_current} + 86400]
# WHOLE DAY EVENTS:
for i in `ls *.ics`; do
if [ `awk 'NR == 9' ${i} | sed 's+.*:++g' | wc -m` = 10 ]
then
Epoch_event_tmp=`awk 'NR == 9' ${i} | sed 's+.*:++g' | sed 's/./\/&/5' | sed 's/./\/&/8'`
Epoch_event=`date -j -f date -j -f "%Y/%m/%d %T" "${Epoch_event_tmp} 00:00:00" +"%s"`
if [ "${Epoch_current}" \< "${Epoch_event}" ] && [ "${Epoch_24}" \> "${Epoch_event}" ]
then
echo ${Epoch_event} >> ${tmpdir}/1_epoch.txt
echo `awk 'NR == 9' ${i} | sed 's+.*:++g' | sed 's/./\/&/5' | sed 's/./\/&/8'` >> ${tmpdir}/2_time.txt
echo `awk 'NR == 11' ${i} | sed 's+.*:++g'` >> ${tmpdir}/3_event.txt
echo `awk 'NR == 14' ${i} | sed 's+.*:++g'` >> ${tmpdir}/4_location.txt
fi
# TIMED EVENTS
elif [ `awk 'NR == 9' ${i} | sed 's+.*:++g' | wc -m` = 17 ];
then
Epoch_event_date=`awk 'NR == 9' ${i} | sed 's+.*:++g' | sed 's/./\/&/5' | sed 's/./\/&/8' | sed 's/T.*//'`
Epoch_event_time=`awk 'NR == 9' ${i} | sed 's+.*:++g' | sed 's+.*T++g' | sed 's/./\:&/3' | sed 's/./\:&/6'`
Epoch_event=`date -j -f date -j -f "%Y/%m/%d %T" "${Epoch_event_date} ${Epoch_event_time}" +"%s"`
if [ "${Epoch_current}" \< "${Epoch_event}" ] && [ "${Epoch_24}" \> "${Epoch_event}" ]
then
echo ${Epoch_event} >> ${tmpdir}/1_epoch.txt
echo `awk 'NR == 9' ${i} | sed 's+.*:++g' | sed 's/./\/&/5' | sed 's/./\/&/8'` >> ${tmpdir}/2_time.txt
echo `awk 'NR == 11' ${i} | sed 's+.*:++g'` >> ${tmpdir}/3_event.txt
echo `awk 'NR == 14' ${i} | sed 's+.*:++g'` >> ${tmpdir}/4_location.txt
fi
fi
done
The error is associated with the line:
Quote:
Epoch_event=`date -j -f date -j -f "%Y/%m/%d %T" "${Epoch_event_date} ${Epoch_event_time}" +"%s"`
Thanks in advance!
M0s..
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Solaris 10 doesn't seem to like me a lot. I am trying to run a simple script to accept date and return epoch of that date:
#!/usr/bin/perl -w
use strict;
use Time::ParseDate;
my($date1)="Mon Mar 27 05:54:08 CDT 2009";
chomp $date1;
#Convert to seconds since start of epoch
my $time1 =... (3 Replies)
Discussion started by: pavanlimo
3 Replies
2. Shell Programming and Scripting
Hi all!
I have a "simple" problem:
I want to convert a date and time string (YYYYMMDDhhmmss) to epoch (unix time) in a shellscript.
I want to use the "date/time" string as an input to the script, eg:
scriptname.sh 20090918231000 and get the epoch format echoed out.
Is there an... (3 Replies)
Discussion started by: condmaster
3 Replies
3. Shell Programming and Scripting
System: HP-UX
Kornshell
Perl is installed, but not POSIX
Hello,
I am calculating a future date/time. To do this I take the system date in epoch format and add to it. I now need to take the new epoch date and convert it to MMDDYYHHmm format.
Any help with this is greatly appreciated. (4 Replies)
Discussion started by: LetsGoPens
4 Replies
4. Shell Programming and Scripting
Could someone please explain how to get a formatted date from the unix epoch (the number of seconds since Jan 1, 1970)
For example.,
If the input is 1297969816, then the output should be 2011-02-17 in YYYY-MM-DD formatted manner.
I am using AIX sh shell. Tried date -d and date --date, these... (4 Replies)
Discussion started by: Jesinth Nirmal
4 Replies
5. Shell Programming and Scripting
I am trying get time difference of two dates in secs. Initially I want to convert a standard date format to epoch for two dates and then subtract the two epoch dates.
Example :
date -d "2007-09-01 17:30:40" '+%s'
But this gives me below error
date: illegal option -- d
Usage: date
OS: AIX... (6 Replies)
Discussion started by: bpaac
6 Replies
6. Programming
Hi all ,
I need to know how to convert a time stamp entered by the user to be converted to GMT/UTC(epoch time) using mktime() and gmtime()
for exapample the input will be put in the form
ptm.tm_sec = 0;
ptm.tm_min = 59;
ptm.tm_hour = 11;
ptm.tm_mday = 20;... (2 Replies)
Discussion started by: ada
2 Replies
7. Shell Programming and Scripting
i can probably script this in bash, but, i was wondering, does anyone know of a simple way to translate a given time to epoch?
date -d@"29/Oct/2013:17:53:11"
the user would specify the date: 29/Oct/2013:17:53:11
and the script will simply interpret that to epoch: 1348838383 (this is just... (4 Replies)
Discussion started by: SkySmart
4 Replies
8. Shell Programming and Scripting
Need assistance in converting an epoch time to Julian date
To get epoch
perl -e 'use Time::Local; print timelocal(1,5,2,12,10,2008), "\n"' (3 Replies)
Discussion started by: ajayram_arya
3 Replies
9. Shell Programming and Scripting
so i have to perform a certain task at set times. for instance, i need to run a job at 12:30am every night, and other jobs, i only need to have them run on saturdays.
how do i manipulate the date command to give me the epoch equivalence of what 12:30am would be every day?
im looking for a... (3 Replies)
Discussion started by: SkySmart
3 Replies
10. Shell Programming and Scripting
I am not able to pass date stored in a variable as an argument to date command. I get current date value for from_date and to_date
#!/usr/bin/ksh
set -x
for s in server ; do
ssh -T $s <<-EOF
from_date="12-Jan-2015 12:02:09"
to_date="24-Jan-2015 13:02:09"
echo \$from_date
echo... (7 Replies)
Discussion started by: raj48
7 Replies
LEARN ABOUT LINUX
shtool-subst
SHTOOL-SUBST.TMP(1) GNU Portable Shell Tool SHTOOL-SUBST.TMP(1)
NAME
shtool-subst - GNU shtool sed(1) substitution operations
SYNOPSIS
shtool subst [-v|--verbose] [-t|--trace] [-n|--nop] [-w|--warning] [-q|--quiet] [-s|--stealth] [-i|--interactive] [-b|--backup ext]
[-e|--exec cmd] [-f|--file cmd-file] [file] [file ...]
DESCRIPTION
This command applies one or more sed(1) substitution operations to stdin or any number of files.
OPTIONS
The following command line options are available.
-v, --verbose
Display some processing information.
-t, --trace
Enable the output of the essential shell commands which are executed.
-n, --nop
No operation mode. Actual execution of the essential shell commands which would be executed is suppressed.
-w, --warning
Show warning on substitution operation resulting in no content change on every file. The default is to show a warning on substitution
operations resulted in no content change on all files.
-q, --quiet
Suppress warning on substitution operation resulting in no content change.
-s, --stealth
Stealth operation. Preserve timestamp on file.
-i, --interactive
Enter interactive mode where the user has to approve each operation.
-b, --backup ext
Preserve backup of original file using file name extension ext. Default is to overwrite the original file.
-e, --exec cmd
Specify sed(1) command directly.
-f, --file cmd-file
Read sed(1) command from file.
EXAMPLE
# shell script
shtool subst -i -e 's;(c) ([0-9]*)-2000;(c) 1-2001;' *.[ch]
# RPM spec-file
%install
shtool subst -v -n
-e 's;^(prefix=).*;1 $RPM_BUILD_ROOT%{_prefix};g'
-e 's;^(sysconfdir=).*;1 $RPM_BUILD_ROOT%{_prefix}/etc;g'
`find . -name Makefile -print`
make install
HISTORY
The GNU shtool subst command was originally written by Ralf S. Engelschall <rse@engelschall.com> in 2001 for GNU shtool. It was prompted
by the need to have a uniform and convenient patching frontend to sed(1) operations in the OpenPKG package specifications.
SEE ALSO
shtool(1), sed(1).
18-Jul-2008 shtool 2.0.8 SHTOOL-SUBST.TMP(1)