I am having major issues with nfs, in that server-1 has to mount a file from server-2 before an application owned by another user can operate. The applications will appear to load without the mounted share but they will be just going through the motions and the application will not actually be working. The troubleshooting is difficult because the end users always send trouble tickets about the wrong thing.
I wanted to develop a script that would check to see if the mount was present and if it wasn't present, run the mount script. Since the application started by the other user would need to be restarted, I want to automatically restart those pieces, as their proper user, and then keep the checking script checking every 5 minutes for status. If the mount is still present, the script will just do nothing.
This must be somewhere where the root and the spacial user can gain access, and so for testing sake it is in my own user $HOME directory
This is where I am at the moment:
import os
import time
def main():
x = 5
y = 0
while y < x:
waa = os.system('mount | grep "sda18"') # Checks for existing mount
# maa = os.system('mount') # This line produces a print line of output of mount
print waa, "<- This is the content of the waa variable"
if waa == 256:
#print('blagh')
f = open('tettt.txt','a')
eee = os.system('echo `date` >> tettt.txt')
f.write('\n')
#f.write('eee')
f.close()
#print file('tettt.txt').read() # Scaffolding
s = 's'
s = sysuser(s)
print '%s is the user\n' % (s)
time.sleep(3)
x = x-1
def sysuser(s):
s = str(os.system('whoami'))
L = 'should be a user name'
print s, L
if str(os.system('whoami')) == 'root':
os.system('su - halton')
print os.system('whoami'), L
os.system('touch file.1.txt')
os.system('ls -l')
os.system('exit')
elif os.system('whoami') == 'halton':
print 'I am the Halton UsEr'
print os.system('whoami'), L
os.system('touch file.1.txt')
os.system('ls -l')
os.system('exit')
else:
print 'cannot become special user'
return s
main()
#Successful output (mount is present)
halton@halton-1:~/Desktop/innovator/bin/LyrasisCode$ ./mounty.py
/dev/sda5 on / type ext4 (rw,errors=remount-ro) # This should not be printing at all
0 <- This is the content of the waa variable
Output as root: (mount is missing)
256 <- This is the content of the waa variable
root
0 should be a user name
root
root
cannot become special user
0 is the user
==============
output as halton user (should be going to the elif)
256 <- This is the content of the waa variable
halton
0 should be a user name
halton
halton
cannot become special user
0 is the user #output of line 21
=============
What I expected the system outputs for whoami to be:
halton@halton-1:~/Desktop/innovator/bin/LyrasisCode$ whoami
halton
halton@halton-1:~/Desktop/innovator/bin/LyrasisCode$ sudo whoami
root
If the mount is present, waa=0, if it is not present, waa=256, so it is apparently returning 0 for Boolean True and 256 for False. When I set the test to a "sda18," which is not present in the output of mount, the script is writing the proper environmental date variable content to the file noted.
Why isn't the waa variable value a string?
Why isn't the s variable a username string?