trouble with script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting trouble with script
# 1  
Old 10-17-2002
trouble with script

I'm having a little trouble finishing up this script any help would be great.

My system is SCO OpenServer Enterprise System (ver 5.0.5m) and i'm using sh

This script checks todays date and goes and downloads a file with yesterdays date in the name.

---start----
Server="ipaddresshere"
usern="usernamehere"
pword="passwordhere"
day=`eval date +%Y%m`
tmp1=`eval date +%d`
num=`eval echo $tmp1 - 1 | bc`
tmp2=$day$num
file=filename_$tmp2.txt
cd /tmp
ftp -i -n $Server <<here
user $usern $pword
binary
cd folder1
cd folder2
get $file
quit
here
exit
---end----
Now my problem is what happens on the first of the month... how do i make this script use the 30th or the 31th on the first of the month.

Any help would be great.

Thanks.
# 2  
Old 10-17-2002
whegra,

I believe there are versions of "date" out there that provide date subtraction functionality, but here's a thought:

YES_DAY=0
TODAY=$(date +%d)

if [ ${TODAY} = 01 ]
then
[ ${MONTH} = "01" ] && YES_DAY=31
[ ${MONTH} = "02" ] && YES_DAY=31
[ ${MONTH} = "03" ] && YES_DAY=28
[ ${MONTH} = "04" ] && YES_DAY=31
[ ${MONTH} = "05" ] && YES_DAY=30
[ ${MONTH} = "06" ] && YES_DAY=31
[ ${MONTH} = "07" ] && YES_DAY=30
[ ${MONTH} = "08" ] && YES_DAY=31
[ ${MONTH} = "09" ] && YES_DAY=31
[ ${MONTH} = "10" ] && YES_DAY=30
[ ${MONTH} = "11" ] && YES_DAY=31
[ ${MONTH} = "12" ] && YES_DAY=30
fi

There may be an easier way, but I thought I'd toss this out there to get you started. You may also want to modify the above to account for leap years.

You can check out the following page for some more ideas/scripts:

http://unix.about.com/library/weekly/aa070901a.htm

Hope this helps!


Biker
Systems/Network Administrator
LiveFire Labs - Hands-On Technical e-Learning
www.LiveFireLabs.com
# 3  
Old 10-17-2002
P.S. Using a case statement in place of the multiple tests will reduce the amount of code needed.


Biker
Systems/Network Administrator
LiveFire Labs - Hands-On Technical e-Learning
www.LiveFireLabs.com
# 4  
Old 10-17-2002
I posted a script that can handle date arithmetic. You can find it in this post.
# 5  
Old 10-17-2002
Thanks Guys,

That was exactly what I needed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Trouble with Shell Script Compressing file

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: You will create a shell script that performs the following action: Use a parameter to pass a file that... (5 Replies)
Discussion started by: Luvs2drnk
5 Replies

2. Shell Programming and Scripting

Having trouble with My Bash Script, need Help debugging

Hello Friends I am having trouble with my script below. I will describe the problems below the code box. I am hoping that some of the experts here can help me. #!/bin/bash #========================================================================================================= # Rsync File... (8 Replies)
Discussion started by: jdavis_33
8 Replies

3. Shell Programming and Scripting

I am having trouble with this count script

I have to display the file name followed by the line count then work count. I am able to display it in the opposite order, but can figure out how to switch it. Can anyone help me with this it would be greatly appreciated. My code is as follows: #!/bin/bash # #Conts and displays the... (5 Replies)
Discussion started by: football12345
5 Replies

4. Shell Programming and Scripting

trouble looping in script

I am having problem looping this script I want to give the user option to decide if they want to continue after each entry but then also loop it back to beginning so they can more to content of there testcase they just created. I fam new to scripting so loops are little tricky for me. code I... (7 Replies)
Discussion started by: andrew.p.mcderm
7 Replies

5. Shell Programming and Scripting

find and copy script trouble

Hi guys First thing to say is that I am entirely new to Shell Scripting and am trying to write a script to do something I thought would be relatively simple, but has escaped me. Essentially, I want to take file name information from a list, find the files listed and then copy the results into... (0 Replies)
Discussion started by: acheron
0 Replies

6. UNIX for Dummies Questions & Answers

trouble with snmpwalk script

I am using a line of code that I borrowed from someone else's script, in a script to monitor changes in my local network. It works but it takes too long to pick up the changes. snmpwalk -v 2c -c PASSWORD -Oq 10.0.1.1 RFC1213-MIB::atPhysAddress The snmp server is my apple router. If I monitor... (7 Replies)
Discussion started by: chancho
7 Replies

7. Homework & Coursework Questions

unix script trouble

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: Hi I am new to unix and need some help, the main reason I am here is because i need basic unix knowledge The... (2 Replies)
Discussion started by: krolike
2 Replies

8. Shell Programming and Scripting

Trouble With Script When Using a timerange in AM that spans into PM

I have a script where a user provides a date, start time and end time. The script will take these values and scan a log file to search for key words in the log file that fall within the time range. When a user uses AM times (Example: 700 to 900 - this is 7am to 9am) as a range or PM times... (7 Replies)
Discussion started by: biddieboy
7 Replies

9. Shell Programming and Scripting

trouble making a useradd script

i'm new to scripting in unix and am trying to make a script to add a user and an encrypted password for them. this is what i have and it isn't giving me any errors, but when i try to login with the new user, the password doesn't work. i'm hoping someone can point me in the right direction ... (1 Reply)
Discussion started by: patt4179
1 Replies

10. Shell Programming and Scripting

trouble in running script

HI admin unix, I'm from indonesia that currently work as system admin for server under AIX/UNIX environment. I have some trouble when running script as follow : ## vdate() { sqlplus -s ${MMUSER}/${PASSWORD} <<-eot|grep -v '^$' set heading off feedback off select... (2 Replies)
Discussion started by: cahyo3074
2 Replies
Login or Register to Ask a Question