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 Wed 20 Aug 2014, 06:57
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 Posts_count  
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 MSNM 
GustavoYz


Joined: 07 Jul 2010
Posts: 895
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 MSNM 
GustavoYz


Joined: 07 Jul 2010
Posts: 895
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: 513

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: 2505
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: 895
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:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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