Scripting problems


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripting problems
# 8  
Old 09-12-2005
to check if today is 'monday'....
Code:
#!/bin/ksh

# set your 'NOT to run day' here: Sun...Sat [1..7]
# 2 is Monday
not2run='2'

if (( $(date +%u) == not2run )) ; then
   echo "Cannot run today"
else
   echo "Can run today"
fi

or as tmarikle has suggested - must have been typing at the same time.
# 9  
Old 09-12-2005
Quote:
Originally Posted by vgersh99
to check if today is 'monday'....
Code:
...
# set your 'NOT to run day' here: Sun...Sat [1..7]
# 2 is Monday
not2run='2'

if (( $(date +%u) == not2run )) ; then
...

My system shows that Monday = 1 when I run man strftime.
# 10  
Old 09-12-2005
Thanks to everyone for the info.

Im fairly new to scripts what does the %a stand for? id there anyway to simplify the if condition such as:

if today=tuesday
then run myscript
# 11  
Old 09-12-2005
Quote:
Originally Posted by tmarikle
My system shows that Monday = 1 when I run man strftime.
different locale I guess:
Code:
     %u        Weekday  as  a  decimal  number  [1,7],   with   1
               representing Sunday.

# 12  
Old 09-12-2005
Quote:
Originally Posted by lewisoco
Thanks to everyone for the info.

Im fairly new to scripts what does the %a stand for? id there anyway to simplify the if condition such as:

if today=tuesday
then run myscript
I referenced %A, which is different then %a.
When I look up date in the man pages, +format refers me to strftime(3C). man strftime yields:

Code:
...
     %a    Locale's abbreviated weekday name.

     %A    Locale's full weekday name.
...

My earlier example is as abbreviated as you probably want but:
Code:
if [ $(date +%A) == Monday ]
then
    echo "Can't run on Mondays"
    exit 2
fi

could be written as this but it's less intuitive if you are new:

Code:
[ $(date +%A) == Monday ] && exit 2

Quote:
Originally Posted by vgersh99
different locale I guess:
It looks like you are right about Locale; I guess I wouldn't want to get used to scripting tests using 1=Monday or 2=Monday without knowing my system's locale if Monday was a bad day to run scripts. Smilie
# 13  
Old 09-12-2005
Quote:
Originally Posted by vgersh99
different locale I guess:
This change was introduced by XPG4. 1=Sunday is the old way and 1=Monday is the new way. From the Solaris 9 strftime man page:
Code:
     The conversion specification  for  %u  was  changed  in  the
     Solaris 8 release. This change was based on the XPG4 specif-
     ication.

I think that HP-UX made the change at 11.0.
# 14  
Old 09-12-2005
Quote:
Originally Posted by Perderabo
This change was introduced by XPG4. 1=Sunday is the old way and 1=Monday is the new way. From the Solaris 9 strftime man page:
Code:
     The conversion specification  for  %u  was  changed  in  the
     Solaris 8 release. This change was based on the XPG4 specif-
     ication.

I think that HP-UX made the change at 11.0.
Ah, I see - I tested it on Solaris 7
Good to know - thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Having issues finishing up a few scripting problems. A little help would be awesome

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 4. Recall that the env command provides a list of various environment variables available to you. Two of those... (5 Replies)
Discussion started by: megachuk
5 Replies

2. Shell Programming and Scripting

100 interesting shell scripting problems

Hi all, I'm just learning to write shell scripts (new to the whole UNIX thing) and I'm wondering if anyone would like to help me create a resource to help me, and others like me, learn scripting. It would be something like "100 interesting shell scripting problems". All I need are... (7 Replies)
Discussion started by: nickednamed
7 Replies

3. UNIX for Dummies Questions & Answers

Code commenting Problems in shell scripting

Hi Friends, I Want to comment one line of code from below code. DBA_ORACLE_USER=`DB.sh -u -a User` DBA_ORACLE_PWORD=`DB.sh -p -a User` sqlplus /nolog <<-END > ${logfile} 2>&1 WHENEVER OSERROR EXIT 9 WHENEVER SQLERROR EXIT SQL.SQLCODE connect... (3 Replies)
Discussion started by: as234301
3 Replies

4. Shell Programming and Scripting

Execution problems with scripting

Hi, I am new to scripting.I had one problem infront of me.I tried in many ways with minimal knowledge........Kindly help me. Description: I want a shell script where it has to read an input.txt file and need to remove duplicate lines and the result need to kept in output.txt file. input... (5 Replies)
Discussion started by: bhas
5 Replies

5. Shell Programming and Scripting

Unix scripting problems

Hi, In my unix server, i received a file in /usr/data/xmit location. i want to write a unix script after file reached. So how can i write a one line code which chceks the presence of the file? and second line line should take the status of the prevous line. like below. Line 1: checks for the... (16 Replies)
Discussion started by: JSKOBS
16 Replies

6. Shell Programming and Scripting

Execution problems with grep command in scripting

Hi All, I was looking for grep command option which can exactly matches the word in a file, for examples you may be seeing one word that is also in another word, there might be lkk0lv23 and a lkk0lv234 in which case lkk0lv23 will put BOTH hosts from the grep in. I was using this in a bash... (2 Replies)
Discussion started by: bobby320
2 Replies

7. Shell Programming and Scripting

Shell scripting problems - Commands not on local machine

Hello all- I have done a lot of searching tonight, but all leads seem to be dead ends. Forgive me if this has been covered, but I've searched the forum and the internet. I am having trouble building a shell script which uses SSH to login to our schools 1024 cluster grid. The issue that I am... (1 Reply)
Discussion started by: Sagan
1 Replies

8. Shell Programming and Scripting

Beginner bash scripting - a few problems

Hey Guys, I am creating a bash script on my freeBSD box, the script should basically ask the user to enter a username and domain. The script will take this information and basically append alot of information to config files so the user can receive email from that domain and create a web site at... (1 Reply)
Discussion started by: traxy
1 Replies

9. Shell Programming and Scripting

shell scripting on unix/mysql problems

Hi, I have written a shell script for oracle on unix that does a df for specific files, and then will display the size, Avail, % used and the difference from yesterday to today. I have been asked to place it on some MySql databases that run onn unix and linux also, but when I try to run them I... (2 Replies)
Discussion started by: cat55
2 Replies

10. Shell Programming and Scripting

Scripting file permission problems...

Hello all - I have two systems. 1) Linux box running Redhat 8.0 2) Tru64 box running V4.0f From the Linux box I am remotely mounting a directory (nfs mount) that resides on the Tru64 machine. The directory that is nfs mounted contains two subdirectories: my_dir1 my_dir2 I want... (3 Replies)
Discussion started by: Heron
3 Replies
Login or Register to Ask a Question