bluefire78
Programmer
Hello, I'm pretty much a newbie at shell scripting. I'd like to write a script that includes some of the following actions. I'd be grateful if you can give me any pointers.
1) read into a variable the complete path to a folder; e.g.
ls foo
.
..
blahblah
---> parse /home/me/foo/blahblah into a variable which I can use. I know there is only one folder that will be returned from the ls; its name, however, is unpredictable.
2) parse the following to ensure that the file "thefile" has the lowest number, of files, inside [ ]. It will not always appear in exactly the same place in the listing, but it will always be named "thefile", and will be the only one to be named such.
docommand
Directory listing of /
d--------- 0 0 0 2048 Mar 13 2004 [ 278 02] .
d--------- 0 0 0 2048 Mar 13 2004 [ 278 02] ..
d--------- 0 0 0 2048 Mar 13 2004 [ 279 02] AFOLDER
Directory listing of /AFOLDER/
d--------- 0 0 0 2048 Mar 13 2004 [ 279 02] .
d--------- 0 0 0 2048 Mar 13 2004 [ 278 02] ..
---------- 0 0 0 14336 Mar 13 2004 [ 7060 00] afile;1
---------- 0 0 0 14336 Mar 13 2004 [ 280 00] thefile;1
---------- 0 0 0 13871104 Mar 13 2004 [ 287 00] afile;1
---------- 0 0 0 83968 Mar 13 2004 [2187472 00] afile;1
---------- 0 0 0 83968 Mar 13 2004 [ 7067 00] afile;1
---------- 0 0 0 1859584 Mar 13 2004 [ 7108 00] afile;1
---------- 0 0 0 1073453056 Mar 13 2004 [ 8016 00] afile;1
---------- 0 0 0 1073618944 Mar 13 2004 [ 532163 00] afile;1
---------- 0 0 0 1073629184 Mar 13 2004 [1056391 00] afile;1
---------- 0 0 0 1073373184 Mar 13 2004 [1580624 00] afile;1
---------- 0 0 0 169451520 Mar 13 2004 [2104732 00] afile;1
---> TRUE
3) If the output of du-k gives a size greater than X, then do something. So I also need to parse the output:
du -k /afolder
27 /afolder/anotherfolder
6805648 /afolder/anotherfolder
6805676 /afolder
---> (6805676 > x) = TRUE
1) read into a variable the complete path to a folder; e.g.
ls foo
.
..
blahblah
---> parse /home/me/foo/blahblah into a variable which I can use. I know there is only one folder that will be returned from the ls; its name, however, is unpredictable.
2) parse the following to ensure that the file "thefile" has the lowest number, of files, inside [ ]. It will not always appear in exactly the same place in the listing, but it will always be named "thefile", and will be the only one to be named such.
docommand
Directory listing of /
d--------- 0 0 0 2048 Mar 13 2004 [ 278 02] .
d--------- 0 0 0 2048 Mar 13 2004 [ 278 02] ..
d--------- 0 0 0 2048 Mar 13 2004 [ 279 02] AFOLDER
Directory listing of /AFOLDER/
d--------- 0 0 0 2048 Mar 13 2004 [ 279 02] .
d--------- 0 0 0 2048 Mar 13 2004 [ 278 02] ..
---------- 0 0 0 14336 Mar 13 2004 [ 7060 00] afile;1
---------- 0 0 0 14336 Mar 13 2004 [ 280 00] thefile;1
---------- 0 0 0 13871104 Mar 13 2004 [ 287 00] afile;1
---------- 0 0 0 83968 Mar 13 2004 [2187472 00] afile;1
---------- 0 0 0 83968 Mar 13 2004 [ 7067 00] afile;1
---------- 0 0 0 1859584 Mar 13 2004 [ 7108 00] afile;1
---------- 0 0 0 1073453056 Mar 13 2004 [ 8016 00] afile;1
---------- 0 0 0 1073618944 Mar 13 2004 [ 532163 00] afile;1
---------- 0 0 0 1073629184 Mar 13 2004 [1056391 00] afile;1
---------- 0 0 0 1073373184 Mar 13 2004 [1580624 00] afile;1
---------- 0 0 0 169451520 Mar 13 2004 [2104732 00] afile;1
---> TRUE
3) If the output of du-k gives a size greater than X, then do something. So I also need to parse the output:
du -k /afolder
27 /afolder/anotherfolder
6805648 /afolder/anotherfolder
6805676 /afolder
---> (6805676 > x) = TRUE