- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - HP-UX
- >
- System Administration
- >
- Re: Need help in Shell scripting
-
- Forums
-
Blogs
- Hybrid Cloud
- Edge
- Data & AI
- Working in Tech
- AI Insights
- Alliances
- Around the Storage Block
- Behind the scenes at Labs
- Careers in Tech
- HPE Storage Tech Insiders
- Inspiring Progress
- IoT at the Edge
- My Learning Certification
- OEM Solutions
- Servers: The Right Compute
- Shifting to Software-Defined
- Telecom IQ
- Transforming IT
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Russia
- HPE Blog, UK & Ireland
- Blogs
-
Quick Links
- Community
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Contact
- Email us
- Tell us what you think
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-27-2006 05:42 PM
08-27-2006 05:42 PM
I just born new in Shell scripting., I gota to know, If Im giving "cal 7 1950", it should gimme the number of days in that calender.
Anyways please..
WH..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-27-2006 06:17 PM
08-27-2006 06:17 PM
Re: Need help in Shell scripting
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-27-2006 06:18 PM
08-27-2006 06:18 PM
Re: Need help in Shell scripting
and you see all month's of day of the year
1950
Good Luck,
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-27-2006 06:27 PM
08-27-2006 06:27 PM
Re: Need help in Shell scripting
I need a script/command/function(interactive), using which, If I give the "Month and Year" as input, I should just give the output as "The month/Yr which you have typed has got XY days"...I just need the number of days, if I give any month/yr..
WH..
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-27-2006 06:57 PM
08-27-2006 06:57 PM
Re: Need help in Shell scripting
baan01:/#date
Mon Aug 28 10:01:44 EETDST 2006
## Work out what yesterday's date was
if [ "${DAY}" = "01" ]
then
case ${MTH} in
Jan)SEARCH_MTH=Dec;((SEARCH_YEAR=YEAR-1));SEARCH_DAY=31;
;
Feb)SEARCH_MTH=Jan;SEARCH_YEAR=${YEAR};SEARCH_DAY=31;;
Mar)SEARCH_MTH=Feb;SEARCH_YEAR=${YEAR};SEARCH_DAY=28;;
Apr)SEARCH_MTH=Mar;SEARCH_YEAR=${YEAR};SEARCH_DAY=31;;
May)SEARCH_MTH=Apr;SEARCH_YEAR=${YEAR};SEARCH_DAY=30;;
Jun)SEARCH_MTH=May;SEARCH_YEAR=${YEAR};SEARCH_DAY=31;;
Jul)SEARCH_MTH=Jun;SEARCH_YEAR=${YEAR};SEARCH_DAY=30;;
Aug)SEARCH_MTH=Jul;SEARCH_YEAR=${YEAR};SEARCH_DAY=31;;
Sep)SEARCH_MTH=Aug;SEARCH_YEAR=${YEAR};SEARCH_DAY=31;;
Oct)SEARCH_MTH=Sep;SEARCH_YEAR=${YEAR};SEARCH_DAY=30;;
Nov)SEARCH_MTH=Oct;SEARCH_YEAR=${YEAR};SEARCH_DAY=31;;
Dec)SEARCH_MTH=Nov;SEARCH_YEAR=${YEAR};SEARCH_DAY=30;;
esac
else
SEARCH_MTH=${MTH}
SEARCH_YEAR=${YEAR}
((SEARCH_DAY=DAY-1))
if [ "${SEARCH_DAY}" -lt "10" ]
then
SEARCH_DAY="0${SEARCH_DAY}"
fi
fi
ONE_DAY_BACK="${SEARCH_YEAR}-${SEARCH_MTH}-${SEARCH_DAY}"
TODAY="${SEARCH_YEAR}-${SEARCH_MTH}-${DAY}"
OR;
How to schedule a job on last friday;
## get actual day
DAY=`date +"%d"`
## get the last friday of curren month
EXEC_DAY=`cal | awk 'NF >=6 { last = $6 }; END{ print last }'`
if [ $DAY -ne $EXEC_DAY ]
then
echo " - Not run because is not the last friday - "
exit;
fi
## Here must write your script
## your commands
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-27-2006 07:13 PM
08-27-2006 07:13 PM
Re: Need help in Shell scripting
Jan)SEARCH_MTH=Dec;((SEARCH_YEAR=YEAR-1));SEARCH_DAY=31;;
Feb)SEARCH_MTH=Jan;SEARCH_YEAR=${YEAR};SEARCH_DAY=31;;
In the above sample lines of yours, from wheres the ${YEAR} taken from..?
WH
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-27-2006 07:17 PM
08-27-2006 07:17 PM
Re: Need help in Shell scripting
DAY=`date +%d`
MTH=`date +%m`
YEAR=`date +%Y`
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-27-2006 07:20 PM
08-27-2006 07:20 PM
Re: Need help in Shell scripting
baan01:/#DAY=`date +%d`
baan01:/#echo $DAY
28
baan01:/#MTH=`date +%m`
baan01:/#echo $MTH
08
baan01:/#YEAR=`date +%Y`
baan01:/#echo $YEAR
2006
baan01:/#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-28-2006 07:47 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-28-2006 08:08 PM
08-28-2006 08:08 PM
Re: Need help in Shell scripting
you can use:
#/user/bin/ksh
# day_of_month
MM=${1:-$(date +%m)}
YYYY=${2:-$(date +%Y)}
TEMP=$(cal $MM $YYYY)
DAYS=$(echo $TEMP|awk '{print $NF}')
echo "$MM $YYYY has $DAYS"
#eof
day_of_month
08 2006 has 31
day_of_month 7 1950
7 1950 has 31
it runs fine on hp hp-ux 11i. (It take care leap years of course).
HTH,
Art
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2019 Hewlett Packard Enterprise Development LP