Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to close a ssh session
I have a small script using os.session to run some specific commands. Typically a user will log into the server over SSH and I have the script running as soon as they log in. I wish to be able to close the SSH session when they input the command in the script to leave. Here is my script. What can I use to accomplish this. I do not want the user to get to the command prompt at all. Thanks
import os
clear = os.system("clear")
print ("")
print("CQ Simple Nimbus Command Line system.")
print ("Use these commands with caution.")
print("Enter the number of the command you want to run and press enter.")

while ans:
    1.Check System Date / Time
    2.Restart Date service
    3.Fwconsole restart
    4.Fwconsole Upgrade Modules
    5.Validate Modules
    6.Clean modules
    7.Refresh module signatures
    8.Reset file permissions
    9.PM2 List
    10.Restart Clearly Devices Module
    999.Check for an update to this program
    ans=raw_input("What would you like to do? ")
    if ans=="1":
      check_date = os.system("date")
    elif ans=="2":
      restart_ntpd = os.system("sudo service ntpd restart")
    elif ans=="3":
      fwconsole_restart = os.system("sudo fwconsole restart")
    elif ans=="4":
      Module_update = os.system("sudo fwconsole ma upgradeall")
    elif ans=="5":
      validate = os.system("sudo fwconsole validate")
    elif ans=="6":
      clean = os.system("sudo fwconsole validate --clean")
    elif ans=="7":
      refresh = os.system("sudo fwconsole ma refreshsignatures")
    elif ans=="8":
      file_permissions = os.system("sudo fwconsole chown")
    elif ans=="9":
      pm2_list = os.system("sudo fwconsole pm2 --list")
    elif ans=="10":
      restart_clearly = os.system("sudo fwconsole pm2 --restart='clearlydevices'")
    elif ans=="99":
      Quit = os.system("exit")
      print ("")
      print("Your session is over.")
      print("Please disconnect from the system.")
      ans = None
    elif ans=="999":
      print(" this program is up to date")
      ans = None
       print("\n Not a Valid Choice Try again")

Possibly Related Threads…
Thread Author Replies Views Last Post
  Powershell Session translation to Python; Session code seems to not work Maverick494 1 1,978 Jun-26-2018, 05:16 PM
Last Post: Maverick494

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020