LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-03-2021, 01:38 AM   #1
Vigp72
LQ Newbie
 
Registered: Nov 2021
Posts: 2

Rep: Reputation: Disabled
need help with this question.


The system administrator has to perform a certain task on Saturday of every even week. Write a script that will check the day and week.

how do i go on about this? i have very little knowledge of shell scripts.
 
Old 11-03-2021, 01:59 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 17,204

Rep: Reputation: 5824Reputation: 5824Reputation: 5824Reputation: 5824Reputation: 5824Reputation: 5824Reputation: 5824Reputation: 5824Reputation: 5824Reputation: 5824Reputation: 5824
This looks like a homework question. see LQ rules: https://www.linuxquestions.org/linux/rules.html
Quote:
Do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and searches) and we'll do our best to help. Keep in mind that your instructor might also be an LQ member.
 
Old 11-03-2021, 02:07 AM   #3
GentleThotSeaMonkey
Member
 
Registered: Dec 2016
Posts: 236
Blog Entries: 3

Rep: Reputation: 76
Hints: see man date
Code:
WEEK=`date +"%V"`
if [ $(($WEEK%2)) -eq 0 ]; # %2 zero indicates even 
then
Code:
if [$ date +%w]=6 then
 
1 members found this post helpful.
Old 11-03-2021, 04:13 AM   #4
Vigp72
LQ Newbie
 
Registered: Nov 2021
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by GentleThotSeaMonkey View Post
Hints: see man date
Code:
WEEK=`date +"%V"`
if [ $(($WEEK%2)) -eq 0 ]; # %2 zero indicates even 
then
Code:
if [$ date +%w]=6 then
can you please elaborate?
 
Old 11-03-2021, 04:18 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,971
Blog Entries: 3

Rep: Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102Reputation: 3102
Quote:
Originally Posted by Vigp72 View Post
can you please elaborate?
Yes, but please say which distro this is for, including version.
 
Old 11-03-2021, 05:51 AM   #6
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,037

Rep: Reputation: Disabled
@OP. Be aware that weeks can be counted differently. See description of date conversion specifiers %U, %V and %W in the documentation of the date command.

@GentleThotSeaMonkey. First you use the POSIX syntax, then suddenly the old, legacy arithmetic expansion syntax $[...], currently still only supported by Bash and Zsh, despite having been deprecated since Bash 2.0.

The standard has following to say:
Quote:
In early proposals, a form $[expression] was used. It was functionally equivalent to the "$(())" of the current text, but objections were lodged that the 1988 KornShell had already implemented "$(())" and there was no compelling reason to invent yet another syntax. Furthermore, the "$[]" syntax had a minor incompatibility involving the patterns in case statements.
BTW, cross-post @linux.org.

Last edited by shruggy; 11-03-2021 at 07:07 AM.
 
Old 11-03-2021, 09:16 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 24,296

Rep: Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140Reputation: 7140
Quote:
Originally Posted by Vigp72 View Post
can you please elaborate?
Yes; can you read the man page for the date command as asked, and also show us what you have written/done/tried?? We aren't going to do your homework for you, and you have been given hints and things to start with. Further, there are a TON of bash scripting tutorials you can find with an Internet search. That is how you get knowledge about scripting...especially if you're taking a class to learn it.
 
Old 11-03-2021, 10:01 AM   #8
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,777
Blog Entries: 23

Rep: Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785
Please review the Site FAQ for guidance in asking well formed questions. Especially visit the link from that page, How to Ask Questions the Smart Way for discussion of things to consider when asking others for help.
 
Old 11-03-2021, 09:10 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,925

Rep: Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631
It's that time of year again in the Northern Hemisphere
 
3 members found this post helpful.
  


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
I need help setting up my vms, hypervisor is KVM. I'm new to netowrking please help. Please Help. I need all the smart guys here!!! fromwin2lin Linux - Server 1 09-07-2016 05:31 AM
interview question pls help guys need your help....:) part-2 mortal25 Linux - Newbie 1 08-16-2010 04:21 AM
interview question pls help guys need your help....:) mortal25 Linux - Newbie 2 08-16-2010 04:20 AM
Help I need some help! Email Question... blackicicle Linux - Software 1 04-27-2004 02:17 PM
need help....need help mercury Linux - Software 2 09-29-2001 12:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:00 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
Open Source Consulting | Domain Registration