Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 21 Apr 2014, 00:59
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
Looking for a script that copies files only on Sundays
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [7 Posts]  
Author Message
divisionmd


Joined: 14 Jul 2007
Posts: 606

PostPosted: Mon 04 Mar 2013, 09:40    Post subject:  Looking for a script that copies files only on Sundays  

Hello,

- Anyone handy with bash script can do this:

- from one line: if its sunday -> copy a file from A to B -> if not sunday continue script

easy to do? was thinking of a few crontab methods but interesting to hear what other smart ways there is to do this?

Thanks,

Best regards,
Johan
Back to top
View user's profile Send private message MSN Messenger 
GustavoYz


Joined: 07 Jul 2010
Posts: 886
Location: .ar

PostPosted: Mon 04 Mar 2013, 13:10    Post subject:  

If I'm getting the idea, something like this shuold work:
Code:
if [ $( date | awk '{print $1}' )="sun" ]; then
   cp $A $B && echo "Copied $A... OK"
else
   # rest of the script
fi

Shorter way:
Code:
[ $( date | awk '{print $1}' )="sun" ] && cp $A $B || ./script.sh

_________________

Back to top
View user's profile Send private message 
divisionmd


Joined: 14 Jul 2007
Posts: 606

PostPosted: Tue 05 Mar 2013, 06:02    Post subject:  

Hello GustavoYz,

Thanks!

What about this one: copy A to B on everyday except sunday?

thansk for help,

Best regards,
Johan
Back to top
View user's profile Send private message MSN Messenger 
GustavoYz


Joined: 07 Jul 2010
Posts: 886
Location: .ar

PostPosted: Tue 05 Mar 2013, 10:06    Post subject:  

Hi divisionmd,
Would be the same:
Code:
if [  $( date | awk '{print $1}' )="sun" ]; then
     # something to do only in sundays
 else
     # the rest of the week:
     cp $A $B && echo "Copied $A... OK"
 fi

_________________

Back to top
View user's profile Send private message 
Moose On The Loose


Joined: 24 Feb 2011
Posts: 485

PostPosted: Tue 05 Mar 2013, 11:15    Post subject:  

GustavoYz wrote:
Hi divisionmd,
Would be the same:
Code:
if [  $( date | awk '{print $1}' )="sun" ]; then
     # something to do only in sundays
 else
     # the rest of the week:
     cp $A $B && echo "Copied $A... OK"
 fi



Beware of case. I get:
Tue Mar 5 07:13:27 PST 2013

The first letter is upper case.

To easily ignore case, use grep

Code:

# if (date | grep -q -i "^tue" ) ; then echo "Works today"; fi
Works today
# if (date | grep -q -i "^wed" ) ; then echo "Works today"; fi
#
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2476
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Tue 05 Mar 2013, 11:47    Post subject:  

date --help wrote:
Usage: date [OPTION]... [+FORMAT]
...
FORMAT controls the output. The only valid option for the second form
specifies Coordinated Universal Time. Interpreted sequences are:
...
%u day of week (1..7); 1 is Monday

Code:
if [ $(date +%u) -eq 7 ] ; then echo copy_files; else echo no sunday ; fi

Quote:
# if [ $(date +%u) -eq 7 ] ; then echo sunday; else echo no sunday ; fi
no sunday
#
Feel free to continue this test on next Sunday Very Happy
Back to top
View user's profile Send private message 
GustavoYz


Joined: 07 Jul 2010
Posts: 886
Location: .ar

PostPosted: Tue 05 Mar 2013, 13:39    Post subject:  

Yep, I use Spanish date format, so is all an aproximation.
But the idea is clear, no "cron-magic" is really needed, with date you're on.

_________________

Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [7 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0493s ][ Queries: 11 (0.0049s) ][ GZIP on ]