LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Solaris / OpenSolaris (https://www.linuxquestions.org/questions/solaris-opensolaris-20/)
-   -   -:::Don't understand this small script:::- (https://www.linuxquestions.org/questions/solaris-opensolaris-20/dont-understand-this-small-script-4175474888/)

manalisharmabe 08-27-2013 09:38 AM

-:::Don't understand this small script:::-
 
Hi Guys,

I don't understand this script,

What does this line " cd `ls |grep -v tar`/disks" here????


Code:

-bash-3.00$ /usr/local/bin/sudo cat /users/sysmgr/ios
Password:
#!/usr/bin/bash

cd /opt/SUNWexplo/output/
cd `ls  |grep -v tar`/disks
echo `pwd`
cp iostat_-E.out /users/sysmgr/ionew
diff /users/sysmgr/ionew/iostat_-E.out  /users/sysmgr/ioold/iostat_-E.out >/users/sysmgr/iodiff
if [ -s /users/sysmgr/iodiff ]
then
echo
else
echo `pwd`
cat /dev/null >iostat_-E.out
cd /opt/SUNWexplo/output
echo `pwd`
rm -f `ls |grep explorer.844d540d.server1|grep tar`
h=`ls |grep -v tar`
tar cvf  $h.tar $h
gzip $h.tar
fi
cp /users/sysmgr/ionew/iostat_-E.out /users/sysmgr/ioold


-bash-3.00$

it showing me this errors:-
Code:

Your "cron" job on server1
/usr/local/bin/sudo /users/sysmgr/ios  #HD404710

produced the following output:

/opt/SUNWexplo/output/explorer.844d540d.server1-2013.08.26.00.00
cp: cannot access iostat_-E.out
/opt/SUNWexplo/output/explorer.844d540d.server1-2013.08.26.00.00
/opt/SUNWexplo/output
tar: explorer.844d540d.server1-2013.08.26.00.00: Is a directory
gzip: explorer.844d540d.server1-2013.08.26.00.00 is a directory -- ignored
gzip: iostat_-E.out.gz already has .gz suffix -- unchanged
gzip: stderr.21762.tar: No such file or directory


EDIT:--
This what I have in /opt/SUNWexplo/output/
Code:

-bash-3.00$ cd /opt/SUNWexplo/output/
-bash-3.00$ ls -la
total 12
drwxr-xr-x  3 root    bin          512 Aug 27 14:50 .
drwxr-xr-x  12 root    bin          512 Jul 31 12:25 ..
-r--------  1 root    root          11 Jul 29 02:06 .explastrun
drwx------  20 root    root        512 Aug 27 14:50 explorer.844d540d.amspdmbep31-2013.08.27.07.02
-rw-r--r--  1 root    root          34 Aug 19 02:45 iostat_-E.out.gz
-rw-------  1 root    root          88 Jun 25 10:30 stderr.21762
-bash-3.00$


szboardstretcher 08-27-2013 09:46 AM

Lets see...

cd `ls |grep -v tar`/disks

so its trying to change directory to: (something without 'tar' in it)/disks. it depends on where you run this, whether it will work or not.

pseudo:

ls current directory
grep for names without tar in it
append it to /disks
cd to (result)/disks

manalisharmabe 08-27-2013 09:52 AM

Quote:

Originally Posted by szboardstretcher (Post 5016905)
Lets see...

cd `ls |grep -v tar`/disks

so its trying to change directory to: (something without 'tar' in it)/disks. it depends on where you run this, whether it will work or not.

pseudo:

ls current directory
grep for names without tar in it
append it to /disks
cd to (result)/disks

Does it mean disks is created at "/" ?

szboardstretcher 08-27-2013 09:54 AM

eh.. let me see here..

cd /opt/SUNWexplo/output/; cd `ls |grep -v tar`/disks

So this 'disks' directory is a subdirectory somewhere in /opt/SUNWexplo/output.

so go there, then try a:

find . -name disks

If you'd like to know where the disks directory is.

manalisharmabe 08-27-2013 10:02 AM

Quote:

Originally Posted by szboardstretcher (Post 5016913)
eh.. let me see here..

cd /opt/SUNWexplo/output/; cd `ls |grep -v tar`/disks

So this 'disks' directory is a subdirectory somewhere in /opt/SUNWexplo/output.

so go there, then try a:

find . -name disks

If you'd like to know where the disks directory is.

no its not there, disks is not there.
Code:

-bash-3.00$ ls -la disks
disks: No such file or directory
-bash-3.00$ pwd
/opt/SUNWexplo/output
-bash-3.00$


manalisharmabe 08-27-2013 10:06 AM

This how it produces output when it runs well on other server.

Code:

Your "cron" job on server2
/usr/local/bin/sudo /users/sysmgr/ios    # HD 404710

produced the following output:

/opt/SUNWexplo/output/explorer.833c0503.server2-2013.08.26.00.00/disks
/opt/SUNWexplo/output/explorer.833c0503.server2-2013.08.26.00.00/disks
/opt/SUNWexplo/output
a explorer.833c0503.server2-2013.08.26.00.00/ 0K
a explorer.833c0503.server2-2013.08.26.00.00/rda/ 0K
a explorer.833c0503.server2-2013.08.26.00.00/rda/RDA.log 6K
a explorer.833c0503.server2-2013.08.26.00.00/rda/collect/ 0K
a explorer.833c0503.server2-2013.08.26.00.00/rda/collect/EXPLORER_XPLR_ptch_z_global.txt 189K
a explorer.833c0503.server2-2013.08.26.00.00/rda/collect/EXPLORER_XPLR_pkg_z_global.txt 1545K
a explorer.833c0503.server2-2013.08.26.00.00/rda/collect/EXPLORER_XPLR_cfg_z_global.txt 1645K

Above are just starting few lines of big output of that script.

SAbhi 08-27-2013 11:05 AM

Quote:

cp iostat_-E.out /users/sysmgr/ionew

cp: cannot access iostat_-E.out
Result of a buggy script... you should always make sure the file or dir exists and has sufficient read and write permissions prior to use them anywhere in the script.
So above cp erroris because of insufficient permissions on the file.

Quote:

tar: explorer.844d540d.server1-2013.08.26.00.00: Is a directory
gzip: explorer.844d540d.server1-2013.08.26.00.00 is a directory -- ignored
gzip: iostat_-E.out.gz already has .gz suffix -- unchanged
gzip: stderr.21762.tar: No such file or directory
Again not checked for a file and nor for existing archive.

EDIT:

assuming you dont have sufficient permisions to change the script... so for this to work fine you have to apply correct permissions on the file "*.out" and and rename the .gz file to something else. That should be it.

manalisharmabe 08-28-2013 01:10 AM

[QUOTE=SAbhi;5016930]Result of a buggy script... you should always make sure the file or dir exists and has sufficient read and write permissions prior to use them anywhere in the script.


NO. this scripts works fine on other solaris 10 server.
this script has started giving errors when we upgraded Sun Explorer version from 7.3 to 8.0. on this machine.

jlliagre 08-28-2013 02:44 AM

Then downgrade explorer to 7.3 or upgrade your script to something that work with explorer 8.0.
If there is no such update, find out the people who wrote the script and ask them for support.
If not available, figure out why and what something changed in the directory layout between the explorer releases.

SAbhi 08-28-2013 10:47 AM

[QUOTE=manalisharmabe;5017257]
Quote:

Originally Posted by SAbhi (Post 5016930)
NO. this scripts works fine on other solaris 10 server.
this script has started giving errors when we upgraded Sun Explorer version from 7.3 to 8.0. on this machine.


Actually the script is sure a buggy script.. reasons i have already mentioned in the last post... it was working fine on other servers because they have the required file and permissions set already and hence it executed.. while when you upgraded a server and it dont have the required sets of permissions and already a archive present, the script should have statements checking that..

for the solution i already have mentioned in EDIT section of last comment.

Firerat 08-28-2013 03:51 PM

that script is .. bad and not as in good.


Warning:
I have never used solaris.
The below is Untested...even on gnu/linux
may use 'features' not available to you
no real error checking/reporting..

Code:

#!/usr/bin/bash

Output=/opt/SUNWexplo/output
iostat_err=${Output}/*/disks/iostat_-E.out
LastIOStat=${Output}/.LastIOStat

# initial LastIOStat
[[ ! -e $LastIOStat ]] \
  && ( echo "ffffffffffffffffffffffffffffffff  ${iostat_err}" > $LastIOStat )

function Archive() {
Tar=${Output}/*/
TarExt=.tar.gz

tar avcf ${Tar/%\//$TarExt} -C ${Output}/ */
return $?
}

function Laststat(){
md5sum ${iostat_err} > ${LastIOStat}
return $?
}

[[ -s "${iostat_err}" ]] \
  && (
    md5sum --status -c $LastIOStat || ( Archive && Laststat );exit $?
  ) || exit 0
fi

Notes:
  • tar will overwrite existing archive ( unless you pass append arg.), so no need to delete
  • The above assumes your tar can compress, and is capable of automagical determination of compression program
  • using md5sum to determine if iostat_-E.out changed ( so you get to keep it )
  • No real error checks in above script
  • Warning: it looks like you may have multiple explorer.*.server*, if that is the case then the original nor the above 'deal' with that
  • will do nothing until you determine correct location of iostat_-E.out
    ( or you get some actual IO errors )

manalisharmabe 08-31-2013 07:23 AM

-bash-3.00$ cd /opt/SUNWexplo/output/
-bash-3.00$ ls -la
total 12
drwxr-xr-x 3 root bin 512 Aug 27 14:50 .
drwxr-xr-x 12 root bin 512 Jul 31 12:25 ..
-r-------- 1 root root 11 Jul 29 02:06 .explastrun
drwx------ 20 root root 512 Aug 27 14:50 explorer.844d540d.amspdmbep31-2013.08.27.07.02
-rw-r--r-- 1 root root 34 Aug 19 02:45 iostat_-E.out.gz
-rw------- 1 root root 88 Jun 25 10:30 stderr.21762
-bash-3.00$

Hi Guys,
I changed bash to ksh, as it was initially.
I removed this two files:-
Code:

-rw-r--r--  1 root    root          34 Aug 31 14:14 iostat_-E.out.gz
-rw-------  1 root    root          88 Jun 25 10:30 stderr.21762

from above location and script just ran well , without any error.

I just compared the files with other servers where this scripts runs well and these 2 files were not there.

Hopefully , I think I have got the solution now.

Thanks a lot for all your replies.

SAbhi 08-31-2013 10:26 AM

Thats exactly what you were told in my last post.

manalisharmabe 09-17-2013 12:10 AM

Hi Guys,

I Just reopened this thread due to one query.

Whenever i run this comand /usr/local/bin/sudo /users/sysmgr/ios on command line only


this line /opt/SUNWexplo/output/explorer.833b0e87.server1-2013.09.16.00.00/disks
get produced but when I again run it, it get executed fully like this:-

Code:

opt/SUNWexplo/output/explorer.833c0503.server1-2013.09.16.00.00/disks
/opt/SUNWexplo/output/explorer.833c0503.server1-2013.09.16.00.00/disks
/opt/SUNWexplo/output
a explorer.833c0503.server1-2013.09.16.00.00/ 0K
a explorer.833c0503.server1-2013.09.16.00.00/rda/ 0K
a explorer.833c0503.server1-2013.09.16.00.00/rda/RDA.log 6K
a explorer.833c0503.server1-2013.09.16.00.00/rda/collect/ 0K
a explorer.833c0503.server1-2013.09.16.00.00/rda/collect/EXPLORER_XPLR_ptch_z_global.txt 189K
a explorer.833c0503.server1-2013.09.16.00.00/rda/collect/EXPLORER_XPLR_pkg_z_global.txt 1545K
a explorer.833c0503.server1-2013.09.16.00.00/rda/collect/EXPLORER_XPLR_cfg_z_global.txt 1646K
a explorer.833c0503.server1-2013.09.16.00.00/rda/collect/EXPLORER_XPLR_R00006_sysconfig_lutab.lin 1K
a explorer.833c0503.server1-2013.09.16.00.00/rda/collect/EXPLORER_XPLR_R00007_sysconfig_drv_aac_conf.lin 1K
a explorer.833c0503.server1-2013.09.16.00.00/rda/collect/EXPLORER_XPLR_R00008_sysconfig_drv_aggr_conf.lin 1K
a explorer.833c0503.server1-2013.09.16.00.00/rda/collect/EXPLORER_XPLR_R00009_sysconfig_drv_arp_conf.lin 1K
a explorer.833c0503.server1-2013.09.16.00.00/rda/collect/EXPLORER_XPLR_R00010_sysconfig_drv_audio1575_conf.lin 2K
a explorer.833c0503.server1-2013.09.16.00.00/rda/collect/EXPLORER_XPLR_R00011_sysconfig_drv_audiocs_conf.lin 2K
a explorer.833c0503.server1-2013.09.16.00.00/rda/collect/EXPLORER_XPLR_R00012_sysconfig_drv_audioens_conf.lin 2K
a explorer.833c0503.server1-2013.09.16.00.00/rda/collect/EXPLORER_XPLR_R00013_sysconfig_drv_audiots_conf.lin 2K



In first attempt this is how it attempts in mail in first attempt:-

Code:

Your "cron" job on server1
/usr/local/bin/sudo /users/sysmgr/ios
produced the following output:
/opt/SUNWexplo/output/explorer.833b0e87.server1-2013.09.16.00.00/disks


What could be the problem that it does not hget executed in first run?

Does it mean that it does not send system information to Sun Explorer Portal?

Well, After first run I did check /opt/SUNWexplo/output folder but nothing speacial get created there.

Please advise.

SAbhi 09-17-2013 12:43 AM

Manali,

first of all whenever you are posting a new issue, use a new thread.

Quote:

Whenever i run this comand /usr/local/bin/sudo /users/sysmgr/ios on command line only
i cant say i understood what you posted...

are you running this command command as a cron job or in a terminal seperately ???
if from a cron share the con entry,
also share

Code:

ls -l /opt/SUNWexplo/output/explorer.833c0503.server1-2013.09.16.00.00/disks


All times are GMT -5. The time now is 01:41 AM.