help needed with a small shell script!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers help needed with a small shell script!
# 1  
Old 04-12-2011
help needed with a small shell script!

I have a scenario where i need to look for files of these kind
Code:
filename.log.0
filename.log.1

if the files are present, then no action is to be taken, if not found,
then it shud create/touch files with the same name.

so can anyone help constructing the script for me..appreciate ur help.


Win

Last edited by Yogesh Sawant; 04-14-2011 at 08:31 AM.. Reason: added code tags
win4luv
# 2  
Old 04-12-2011
That's an extremely vague description, with no indication of how the script knows which files to check for and create.
Code:
for N in 1 2 3 4 5
do
        [ -f /path/to/log.file.$N ] || touch /path/to/log.file.$N
done

If this doesn't do what you want, explain why.
# 3  
Old 04-12-2011
help needed with a small shell script!

Thanks for the prompt reply...
Like i have mentioned earlier,

I have files of these kind
Code:
filename.log.0
filename.log.1

so my script shud look for these files, if present, dont do nothing, but if not found, create the files with the above said filenames....

I hope am clear this time around...

Last edited by Yogesh Sawant; 04-14-2011 at 08:32 AM.. Reason: added code tags
win4luv
# 4  
Old 04-13-2011
Quote:
Originally Posted by win4luv
Thanks for the prompt reply...
Like i have mentioned earlier,

I have files of these kind
filename.log.0
filename.log.1
You said all this already, this is no clearer.

Are they really named "filename.log"? Will they always be the same name? How do you get the name?

Where are they stored?

How many of them? Just 0 and 1? Or are there potentially unlimited numbers?

How would the script know when to stop?

Last edited by Corona688; 04-13-2011 at 12:51 PM..
# 5  
Old 04-13-2011
If there are only two filenames:

Code:
for filename in "filename.log.0" "filename.log.1"
do
    if [ ! -f "$[filename}" ]
    then
           touch "${filename}"
   fi
done

# 6  
Old 04-13-2011
help needed with a small shell script!

Thanks for the reply..

yes the names would be the same, I have just given the names for an example..

these are log files and i might be needing a max of 3 files.

I wud try this and update...Thanks a ton Smilie
win4luv
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script - help needed

I want to take out the Z1 value from the lscfg outpu and use the below command to get it lscfg -vl hdisk0 | grep "Device Specific.(Z1)" | awk -F. '{print $NF}' # lscfg -vpl hdisk0 . . Device Specific.(Z0)........0000063268181002 Device Specific.(Z1)........020064a . And it works,... (2 Replies)
Discussion started by: moorthikv
2 Replies

2. Shell Programming and Scripting

Help Needed with Shell Script

I need help writing a Unix shell script that does the following: 1) Searches all of the files in a given directory that have the .acl file extension 2) Redirects the output of the search to a column in a .xls or .cvs file (Note: The column name in the spreadsheet file needs to be named... (2 Replies)
Discussion started by: ijmoore
2 Replies

3. Shell Programming and Scripting

A small help needed in Logrotate

Hi, I wanted to know can a custom script can be made available to run in postroate endscript something like postrotate ./scriptpath/sh-script.sh endscript Is this the correct syntax, or it will require any modification? Thanks in Advance. Neeryan (1 Reply)
Discussion started by: Neeryan
1 Replies

4. Shell Programming and Scripting

Shell script help is needed

I have a file test.txt and i need to grep pattern "A.17" from that file. I know cat test.txt | grep A.17 will return the pattern, but it is returing like # VERSION=A.17 How can i take only A.17 from this if A.17 is found, ... do something if not found ... do something Please... (11 Replies)
Discussion started by: Renjesh
11 Replies

5. Shell Programming and Scripting

Write a small shell script

Hello Forum members, Have a nice day. I have to write a script for the following below scenario. There are 3 applications located in home directory(ie xyz/app) which have multiple directories and files of diff format(.sh,log,other formats). Case 1: I have to find the hardcoded... (8 Replies)
Discussion started by: rajkumar_g
8 Replies

6. Shell Programming and Scripting

Please help to debug a small shell script (maybe AWK problem)?

Hi Buddies, The following is shell scripts which was borrowed from linux box for load average check. it runs good. (this structure is simple, when load average is too high, it will send alert to user) #!/usr/bin/ksh # Set threshold for 1, 5 and 15 minture load avarage # configured for... (4 Replies)
Discussion started by: GreatJerry
4 Replies

7. Shell Programming and Scripting

Small shell script help required

Hi Guys, Please can some one explain me the below part of code. In this code what is the use of the line in Bold. COPY=0 if ; then echo "$CONF exists and is non-empty - backing it up" SUFFIX=`date +%Y%m%d%H%M%S` echo "cp -p $CONF $CONF.$SUFFIX" cp -p $CONF... (4 Replies)
Discussion started by: max29583
4 Replies

8. Shell Programming and Scripting

Very small Shell Script Help...

The following Script takes each extension and determine what category it belongs and then moves it into a directory based on the extension. (for eg. 1.sh, 5.sh, 9.sh together; 4.csh, 120.csh, 6.csh together and 7.ksh, 2.ksh, 59.ksh together) and moves them to their respective directories viz.... (2 Replies)
Discussion started by: marconi
2 Replies

9. Shell Programming and Scripting

what is problem with this small shell script.. case statement related

Hi All, this small script is written to recognize user input character.. it is in small case .. upeer case or is a number... but when i input first capital letter say A.. it always gives small character.... what is the problem. #!/bin/bash echo "Enter the character" read a case $a in )... (2 Replies)
Discussion started by: johnray31
2 Replies

10. Shell Programming and Scripting

Help needed in Shell Script

Hi I have the following columns in my input file which is sorted on ColA colA colB colC colD colE The data is such that for a single colA it can have multiple values of other columns, for eg the data can be colA colB colC ... (1 Reply)
Discussion started by: nvuradi
1 Replies
Login or Register to Ask a Question