[BlueOnyx:25595] Re: Check vsite suspension state from shell

Michael Stauber mstauber at blueonyx.it
Thu Aug 25 12:31:26 -05 2022


Hi Brent,

> Is there a way I can use bash to determine if a vsite is suspended?
An easy, cheap and somewhat inaccurate way is to check the directory 
permissions in /home/.sites/. A suspended Vsite has all rights removed 
for everyone:

#> ls -la /home/.sites/|grep site1|grep "^d---------"|wc -l
1

The above checks /home/.sites/ to see if "site1" has d--------- 
directory permissions. If so, it returns 1. If not, it returns 0.

BUT: This is flawed. What if you have a "site11"? The grep matches on 
that as well. So if you have site11 suspended and site1 is NOT 
suspended? When you use the above you get "1" back, leading you to 
believe site1 is suspended, whereas it was site11 that matched.

The most reliable way is to check CODB. Normally I'd throw a Perl script 
at this, but you can also do it from the shell if it's just one query or 
two:

#> echo "Find Vsite name = site1" | /usr/sausalito/bin/cceclient|grep 
^104| awk '{ print "GET " $3 }' | /usr/sausalito/bin/cceclient | grep 
"102 DATA suspend" | awk '{ print $5 }' | sed 's/\"//g'
1

With the above commands we echo the command ...

Find Vsite name = site1

... to /usr/sausalito/bin/cceclient and if "site1" exists, we get 
something back that looks like this, telling us the Object ID:

104 OBJECT 34

We grep for the leading "104" and use AWK to extract the object ID. We 
then let AWK print us a new GET query for the extracted Object ID. And 
then we pass something like this ...

GET 34

... to /usr/sausalito/bin/cceclient to fetch the Vsite Object of "site1".

Among many other things that returns back the suspend status as either 
this ...

[...]
102 DATA suspend = "0"
[...]

... or this:

[...]
102 DATA suspend = "1"
[...]

So we grep again - this time for "102 DATA suspend" and use AWK yet 
again to extract the 5th element from that return. Which is either ....

"0"

... or ...

"1"

And as a last act we use sed to remove the encapsulating quotation marks.

So this command sequence reliably returns "1" for suspended Vsites and 
"0" for Vsites that are not suspended.

If you query it for a Vsite that doesn't exist, then the returned answer 
is empty.

-- 
With best regards

Michael Stauber



More information about the Blueonyx mailing list