How can I place a for statement....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I place a for statement....
# 1  
Old 08-11-2008
For statement in a shell script

In a script?

I have some folders that contain many files of 8MB or more in size. Every day run "for file in F*; do gzip $file; done"

How can I put this in a script to run automatically?

Last edited by bbbngowc; 08-11-2008 at 12:31 PM..
# 2  
Old 08-11-2008
Use an editor like vi, edit a file and insert your commands, use absolute paths as cron might get upset. Then edit the crontab with crontab -e and edit it accordingly. Your cron editor might be vi too.
# 3  
Old 08-11-2008
Quote:
Originally Posted by bbbngowc
In a script?

I have some folders that contain many files of 8MB or more in size. Every day run "for file in F*; do gzip $file; done"

How can I put this in a script to run automatically?
Imagine someone is searching these forums. They want to put a "for" command in a script. They see a title, "How can I place a for statement..."; how does this help them know if that thread will be helpful for them? What if they search only titles for the words "for" and "script"? Will they find your post?

Please be considerate of others who will come after you (and yourself, if you ever want to find this information if you forget it later!) when choosing your post titles. Others may elect to answer this selfishly-formatted question, but I will not.
# 4  
Old 08-11-2008
Quote:
Originally Posted by BMDan
Imagine someone is searching these forums. They want to put a "for" command in a script. They see a title, "How can I place a for statement..."; how does this help them know if that thread will be helpful for them? What if they search only titles for the words "for" and "script"? Will they find your post?

Please be considerate of others who will come after you (and yourself, if you ever want to find this information if you forget it later!) when choosing your post titles. Others may elect to answer this selfishly-formatted question, but I will not.
Noted.

Now ... to the answer Smilie
# 5  
Old 08-11-2008
Quote:
Originally Posted by zaxxon
Use an editor like vi, edit a file and insert your commands, use absolute paths as cron might get upset. Then edit the crontab with crontab -e and edit it accordingly. Your cron editor might be vi too.

This seemed to have worked:

#!/bin/ksh
for file in /dir/dir2/F*
do
gzip $file
done


I thought that the 'for' statement would've sent the script into a loop or something and wouldn't complete.
# 6  
Old 08-11-2008
No, for just processes a list, and the list in your case are the files being found in with "/dir/dir2/F*".
# 7  
Old 08-12-2008
Quote:
Originally Posted by bbbngowc
In a script?

I have some folders that contain many files of 8MB or more in size. Every day run "for file in F*; do gzip $file; done"

How can I put this in a script to run automatically?
hrmmmm

the script would be like this

Code:
#!/bin/bash
for file in F*; do gzip $file; done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

2. Solaris

What is the best way to copy data from place to another place?

Dear Gurus, I need you to advice or suggestion about the best solution to copy data around 200-300G from serverA(location A) to serverB(location B). Normally, I will share folder and then copy but it takes too long time(about 2 days). Do you have any suggestion or which way should be... (9 Replies)
Discussion started by: unitipon
9 Replies

3. Shell Programming and Scripting

usage of case statement in place of IF elif...

Hi, I need to carry out the back up of the data if exists...(file size not equal to zero) i tried in this way but it is not successful....where am making the mistakes? and if possible can i use case syntax in place of "if" #!/bin/ksh filename=`TZ=CST+24 date +%Y%m%d` ZERO=0... (3 Replies)
Discussion started by: aemunathan
3 Replies

4. Shell Programming and Scripting

Place number with awk

Hello, if I've a list of number 23 34 56 78 how I can place a sequence of ordinated number in a boundary column so 1 23 2 34 3 56 4 78 Thanks in advance! (3 Replies)
Discussion started by: cv313x
3 Replies

5. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

6. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies

7. Shell Programming and Scripting

Getting the value of a line, that changes place

Hi I am trying to get the value of several results in a file called seq032.diag. The values I am looking for is down under Smooth Tracking nodes and is for g01r01 g02r01 s01t02 etc etc. The problem is that when I try to use look for text and tail etc, it works fine in one result file. In... (1 Reply)
Discussion started by: Navigatorchief
1 Replies

8. Solaris

When does LK actually take place?

I appologize in advance, my question would be easly for me to research if I actually had a Solaris server that I had access to. And I am googled out. I am auditing a solaris 9.0 server's passwords (I was sent the passwd and shadow files) and need to know when the *LK*actually happens. In... (0 Replies)
Discussion started by: lerdahl
0 Replies

9. UNIX for Dummies Questions & Answers

How to place restrictions in a directory

I have a directory called sync and the directory path is ftp/exports/sync. What I would like to do is place some documents in sync for external users to view and would like to have access restriction for the sync directory. i.e. login and password. How do I go about doing this in a Unix enviorment.... (3 Replies)
Discussion started by: coburn
3 Replies

10. UNIX for Dummies Questions & Answers

Where do I place ipchain scripts??

Where do I place IPCHAIN scripts on a Mandrake 8.0 computer?? (1 Reply)
Discussion started by: Deuce
1 Replies
Login or Register to Ask a Question

Featured Tech Videos