Sponsored Content
Full Discussion: Who can finish this script?
Top Forums Shell Programming and Scripting Who can finish this script? Post 302851891 by Mohannad on Tuesday 10th of September 2013 03:22:33 AM
Old 09-10-2013
Hello my friend,

I created 6 directories (MMU_01, MMU_02 .... MMU_06) and I distributed 24 files between them (not equally) then I applied this script (after changing the name of directories from SMS_* into MMU_*)

But nothing moved between directories, i.e. the empty directories still empty, and the directory which have 11 files still have the same number.

I think there is something missing in the script.

Please check the out put with me as the following:

Here is the 6 directories + the script file:
Code:
[P550_APP4][root]/Scripts/test> ls -l
drwxr-xr-x    2 root     system         4096 Sep 10 10:04 MMU_01
drwxr-xr-x    2 root     system          256 Sep 10 09:54 MMU_02
drwxr-xr-x    2 root     system          256 Sep 10 09:56 MMU_03
drwxr-xr-x    2 root     system          256 Sep 10 09:56 MMU_04
drwxr-xr-x    2 root     system          256 Sep 10 10:01 MMU_05
drwxr-xr-x    2 root     system          256 Sep 10 09:54 MMU_06
-rwxr-xr--    1 root     system          331 Sep 10 10:06 test.sh

After applying the script, this result appearing:

Code:
[P550_APP4][root]/Scripts/test> ./test.sh
mv MMU_01/dwe.txt MMU_01/dwe.txt
mv MMU_01/dwedwe.txt MMU_01/dwedwe.txt
mv MMU_01/dwesqwsqdwe.txt MMU_01/dwesqwsqdwe.txt
mv MMU_01/dwesqwsqddwedqwe.txt MMU_01/dwesqwsqddwedqwe.txt
mv MMU_01/dwesq45e.txt MMU_02/dwesq45e.txt
mv MMU_01/dwesq45342e.txt MMU_02/dwesq45342e.txt
mv MMU_01/dwesq242e.txt MMU_02/dwesq242e.txt
mv MMU_01/dwesq24e.txt MMU_02/dwesq24e.txt
mv MMU_01/dwe232wqwsq24e.txt MMU_03/dwe232wqwsq24e.txt
mv MMU_01/dwe232w4rqwsq24e.txt MMU_03/dwe232w4rqwsq24e.txt
mv MMU_01/dsqdqw2 MMU_03/dsqdqw2
mv MMU_01/1231 MMU_03/1231
mv MMU_01/97dws MMU_04/97dws
mv MMU_03/rterterte.sh MMU_04/rterterte.sh
mv MMU_03/rtertertewefrwe.sh MMU_04/rtertertewefrwe.sh
mv MMU_03/rterffdstewefrwe.sh MMU_04/rterffdstewefrwe.sh
mv MMU_03/rterfeewe.sh MMU_05/rterfeewe.sh
mv MMU_03/rtesrfeewe.sh MMU_05/rtesrfeewe.sh
mv MMU_03/rtesrf4eewe.sh MMU_05/rtesrf4eewe.sh
mv MMU_04/tyuio.jpg MMU_05/tyuio.jpg
mv MMU_04/tyuiowewew.jpg MMU_06/tyuiowewew.jpg
mv MMU_04/tyuiowewew2dsw.jpg MMU_06/tyuiowewew2dsw.jpg
mv MMU_05/ghgydf.txt MMU_06/ghgydf.txt
mv MMU_05/ghgy.txt MMU_06/ghgy.txt

Then I checked the first directory to make sure, but it still have 11 files!

Code:
[P550_APP4][root]/Scripts/test> cd MMU_01
[P550_APP4][root]/Scripts/test/MMU_01> ls -l
total 0
-rw-r--r--    1 root     system            0 Sep 10 10:04 1231
-rw-r--r--    1 root     system            0 Sep 10 10:04 97dws
-rw-r--r--    1 root     system            0 Sep 10 10:03 dsqdqw2
-rw-r--r--    1 root     system            0 Sep 10 09:54 dwe.txt
-rw-r--r--    1 root     system            0 Sep 10 09:55 dwe232w4rqwsq24e.txt
-rw-r--r--    1 root     system            0 Sep 10 09:54 dwe232wqwsq24e.txt
-rw-r--r--    1 root     system            0 Sep 10 09:54 dwedwe.txt
-rw-r--r--    1 root     system            0 Sep 10 09:54 dwesq242e.txt
-rw-r--r--    1 root     system            0 Sep 10 09:54 dwesq24e.txt
-rw-r--r--    1 root     system            0 Sep 10 09:54 dwesq45342e.txt
-rw-r--r--    1 root     system            0 Sep 10 09:54 dwesq45e.txt
-rw-r--r--    1 root     system            0 Sep 10 09:54 dwesqwsqddwedqwe.txt
-rw-r--r--    1 root     system            0 Sep 10 09:54 dwesqwsqdwe.txt


Please help me, I'm sure something is missing, or something need to be corrected.

---------- Post updated at 02:22 AM ---------- Previous update was at 02:20 AM ----------

Quote:
Originally Posted by MadeInGermany
A good start, but IMHO not correct. One must consider source directories above average and target directories below average...
Yes it is good script, I learned some concepts from Mr. krishmaths.
I appreciate your notes, kindly refer to the previous reply to see the result, and apply your notes into script to fix the problems, because it needs some correction.

Thanks a lot MadeInGermany Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check succeesfull finish of a executable from the sheel script

Hi, I want to know is there a way out wherein we can know that the C++ executable has finished its task. Following is the steps: 1.Shell script calls a executable after setting all the env variables. 2.Now after the executable has done its job(basically to create some outpur files).The... (2 Replies)
Discussion started by: electroon
2 Replies

2. UNIX for Dummies Questions & Answers

how do i finish this last one..

i tried to build a command to replaces the word "include" with "exclude" in each *.h type of file in a certain directory and to display the lines in which the switch happened. i did a command and i dont know why its not working find /usr -name "*.h" -exec sed 's/include/exclude/g' {} \;... (2 Replies)
Discussion started by: newby2
2 Replies

3. UNIX for Advanced & Expert Users

commands do not finish

Hi, I have strange problem executing some command on solaris 5.9 ps command does not finish(hangs) and runs forever without any result. same with cc command too.Please suggest (1 Reply)
Discussion started by: Raom
1 Replies

4. UNIX for Dummies Questions & Answers

Jumpstart finish script (Solaris 10)

Hi there, I wanted to write a finish script for my jumpstart server which creates a ntp.conf file and enables ntp on the client machines during installation. Is that possible? Thanks for the help :) P.S. I'm a real Solaris noob, so do excuse me if I sound like an idiot..lol (1 Reply)
Discussion started by: iman453
1 Replies

5. Shell Programming and Scripting

Finish script help

I am trying to add a finish script that can copy hosts, static routes and a few other files into relevant directories on a client system. These files would be mounted as nfs resource on the client as hosts.hostname, static_route.hostname etc. Script will compare the hostname of the client and copy... (0 Replies)
Discussion started by: c0kazaz
0 Replies

6. Shell Programming and Scripting

finish of file

Hello, I'm doing a script where I'm traveling a file, and moves down line by line, and is copied to another file, up to the line 100, then the smaller file passes to another format ... but the problem I have is that if there are 357 lines for example, file 1 2 i 3, converted correctly but the 4... (1 Reply)
Discussion started by: uri_crack
1 Replies

7. Shell Programming and Scripting

Please help me to finish this scripts

Hi All, Can anyone help me to finish the scripts. this scripts is this scripts will run on crontab in every 4 minutes to get the newest router interface status. I would like to add a function to count the router interface flapping, if more than 2 times in 20 minutes (scripts run 5 times)... (1 Reply)
Discussion started by: momo0617
1 Replies

8. Shell Programming and Scripting

expect ssh script cannot finish and exit

All i am new to linux, and try to have a simple expect script to ssh then telnet to the network equipment, and exit itself. but dont know why i hang at the last $ #!/usr/bin/expect set timeout 10 set arg set arg1 spawn ssh -l UserA 1.1.1.1 expect "assword:"; send "PasSwOrD\r";... (1 Reply)
Discussion started by: samoptimus
1 Replies

9. Shell Programming and Scripting

Cannot execute/finish script because of last line syntax error: unexpected end of file/token `done'

first of all I thought the argument DONE is necessary for all scripts that have or begin with do statements which I have on my script, However, I still don't completely understand why I am receiving an error I tried adding another done argument statement but didn't do any good. I appreciate... (3 Replies)
Discussion started by: wolf@=NK
3 Replies

10. Shell Programming and Scripting

Finish current script and execute next script

Hi, I've come accross a situation where I need to exit from current shell script at the same time I need to start/activate another shell script. How can I do that in KSH ?? Need help !! For example, my script is as below #!/bin/ksh paramFile="/home/someXfile.lst" ] && <<Here I... (1 Reply)
Discussion started by: R0H0N
1 Replies
All times are GMT -4. The time now is 09:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy