UNIX AIX 5.3 Script Help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX AIX 5.3 Script Help
# 1  
Old 09-12-2006
UNIX AIX 5.3 Script Help

Hello all,

I have a few questions regarding a UNIX script I've been asked to write (even though I barely know UNIX!).

I would like to write a script, that when run, will copy a file from one directory to another, copy and rename the same file with a datestamp to an archive directory, and them delete the file from the current directory.

This is what I came up with and was hoping the experts here could throw in their 2 cents. (I'm assuming this works, as I'm still waiting on getting access to the server as well as getting the SSH Tectia Client installed on my workstation):

approve.sh - (name I plan on giving the script)

#PATH variable should include /bin directory ???
#script can then be executed by typing "sh approve filename"
#
#Step 1 - Copy to Prod
#
echo "Copying file $1 to Production Directory"
cp [-fip] $1 $1 /prod/appfolder
#
#Step 2 - Copy to Archive
#
echo "Archiving file $1 to Archive Directory"
DAY=`date +%d`
MONTH=`date +%b`
YEAR=`date +%Y`
cp $1 $1.$MONTH.$DAY.YEAR /archive/unknownfoldername
#
#Step 3 - Delete file (might be able to do this in step 2 with a move)
#
echo "Deleting file $1 from Temporary Directoty"
rm $1
exit 0

Does that look like something that will work? What concerns should I have when it comes to the authority to run the script? Will the person authorized to run the script need read authority to the file? I would like the "approver" who runs this script to have only read access to the file.

As you can tell I'm pretty new to this, so any help would be GREATLY appreciated!

Thanks! Smilie
# 2  
Old 09-12-2006
Lightbulb

why not move the file to a directory then copy the file with the new archive filename? this way you won't have to delete the file anymore.

Code:
#Get current date
dateNow=`date "+%m.%d.%Y"`

#Move file to another folder
mv ${1} /prod/appfolder/${1}

#Copy file with new archive name
cp -p /prod/appfolder/${1} /newfolder/${1}.${dateNow}

the person should at least have a read and execute permission to run this script. use chmod command to change permission of the script.

thanks
# 3  
Old 09-13-2006
Quote:
Originally Posted by inquirer
why not move the file to a directory then copy the file with the new archive filename? this way you won't have to delete the file anymore.

Code:
#Get current date
dateNow=`date "+%m.%d.%Y"`

#Move file to another folder
mv ${1} /prod/appfolder/${1}

#Copy file with new archive name
cp -p /prod/appfolder/${1} /newfolder/${1}.${dateNow}

the person should at least have a read and execute permission to run this script. use chmod command to change permission of the script.

thanks
Thanks very much... I have 2 more questions:

1. I want to be able to put minutes and seconds on the timestamp, is that possible?

2. I want the script to exit with a message if the file isn't present to begin with, how do I do that?

Thanks in advance! Smilie
# 4  
Old 09-14-2006
bump... anyone?
# 5  
Old 09-14-2006
You can get hours, minutes, seconds from the date command. Do a man date. To test whether the file exists in the first place (so you can exit if it doesn't), see man test.
# 6  
Old 09-14-2006
Quote:
Originally Posted by Glenn Arndt
You can get hours, minutes, seconds from the date command. Do a man date. To test whether the file exists in the first place (so you can exit if it doesn't), see man test.
I'd use the "man" command if I could but I currently have zero access to any UNIX resources. Otherwise I'd just log in and start playing around with stuff.

I won't be given access to our dev UNIX box until sometime next week, which is when I'm expected to have this thing ready to go. I know that doesnt make much sense, but it's the situation I've been presented with.

I've modified it to (what I think will) give me the date/time info:

dateNow=`date "+%m.%d.%Y.%HH.%MM.%SS"`

But I've absolutely zero references as to how the test function works or how conditional processing (if.. then.. else) works in these scripts. (I'm a mainframe/VB programmer so I'm familiar with how things work and could probably pseudocode somthing up, but I have no way of testing, and my UNIX server support group refuses to do any programing or assist saying "thats not our job anymore")

Any help would be great... Smilie
# 7  
Old 09-14-2006
They expect you to have code written and ready before you have access to the system? Sounds typical. Smilie

Anyway, I don't know what OS you are using, but you can look up the man pages for darn near anything at http://www.freebsd.org/cgi/man.cgi.

Oh, and for the date stamp, %H.%M.%S will give you HH.MM.SS.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AIX UNIX Script to Replace XML Values

Hi - I've seen variations of this same question asked but I have not been able to find an answer that fits my problem. Please direct me to another post if there already is a solution to this. I'm trying to write a Unix script to dynamically iterate through a flat file and replace a value in... (4 Replies)
Discussion started by: ocbit
4 Replies

2. UNIX for Dummies Questions & Answers

AIX UNIX - script on how to extract from log file with previous date

Hello, I am new to this forum so any assistance would help. I am currently trying to develop a script that extract all data from a log file with has the previous day's date. $ <root@aixtest3> /var/log > more sudo.log May 13 10:52:10 aixtest3 local2:notice sudo: tbrath : TTY=unknown ; ... (14 Replies)
Discussion started by: Kslew82
14 Replies

3. Shell Programming and Scripting

Interactive script through ssh AIX UNIX

I wish to launch a script with ssh command. This script launches a menu. The menu displays well but I can't interact with it. Can you help me :confused: ? (1 Reply)
Discussion started by: khalidou13
1 Replies

4. Shell Programming and Scripting

AIX UNIX (kshell) to Linux Shell Script Migration.

Hi, Could you please let me know what kind of changes/issues commonly occurs at Scripting /command level during AIX Unix (kshell) to Linux shell script migration. (24 Replies)
Discussion started by: Raghuraman.R
24 Replies

5. Shell Programming and Scripting

I want a script to view the complete log information of data stage job from UNIX IBM AIX.

Hi, I am working on data stage 8.7 version and I want a script a to view the all log information of the data stage job from UNIX environment. Can you please help me out by give the script. Thanks in advance... (7 Replies)
Discussion started by: victory
7 Replies

6. AIX

Get Next month in AIX from curent date in unix AIX

How could we derive teh Next month in MON-RR format from current date ie sysdate in UNI AIX sheel script.I coould get a command but i supports only inLinux susse andnotin AIX. I need for Unix AIX.Pls Help. Regards Shiv (2 Replies)
Discussion started by: SHIV75
2 Replies

7. Shell Programming and Scripting

Script to check if SQLLDR has been installed on Unix/Aix servers

How can i check if sqlldr has been installed on my AIX/UNIX mechine? Is there any unix script to check this one out.... (0 Replies)
Discussion started by: msrahman
0 Replies

8. Solaris

which is the best unix? solaris? aix ? hp-unix?

which is the best unix? solaris? aix ? hp-unix? I want to study unix system ? Anyone tell me which is the best? (2 Replies)
Discussion started by: mac2008
2 Replies

9. UNIX for Dummies Questions & Answers

AIX Unix

I have a list of printers which runs into two pages. How can tell if a printer is still valid / in use? I thought of pinging but that would just tell me if the printer was online or not?? (1 Reply)
Discussion started by: mrbr1dgr31
1 Replies

10. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies
Login or Register to Ask a Question