01
2020
10

Server Admin - Ubuntu 16.04 LTS

#!/usr/bin/python3

#!/usr/bin/env python3

import time

import os



  

while True:

    try:

        a=int(input("\nCheck Status press '1'\n\nStart All Services press '2'\n\nStart v2ray VPN press '3'\n\nReboot Server press '4'\n\nClear Syslog and Kernlog press '5'\n\nBackup Server '6'\n\nEnter Your Choice: "))

    except ValueError:

        print("\nHey! You're not entering a number! Please enter the above mentioned number!")

        continue

    else:

        break


if a==2:

    os.system("service apache2 start")

    time.sleep(1)

    os.system("usermod -a -G aid_inet,aid_net_raw mysql")

    print("\nMYSQL has been authorized to android user~\n")

    time.sleep(1)

    os.system("service webmin start")

    print("Webmin has been initiated!\n")

    time.sleep(1)

    os.system("service mysql start")

    print("\n")

    time.sleep(1)

    print("\n")

    os.system("service memcached start")

    time.sleep(1)

    os.system("service v2ray start")


elif a==1:

    os.system("service apache2 status")

    time.sleep(1)

    print("\n")

    os.system("service mysql status")

    time.sleep(1)

    print("\n")

    os.system("service webmin status")

    time.sleep(1)

    print("\n")

    os.system("service memcached status")

    time.sleep(1)

    print("\n")


elif a==3:

    os.system("v2ray")

    

elif a==4:

    print("\nRestarting the server…")

    os.system("unchroot am start -a android.intent.action.REBOOT")

    print("Please wait for a while~\n")


elif a==5:

    os.system("rm -rf kern*.log")

    time.sleep(2)

    os.system("rm -rf syslog*.log")

    print("Syslog and Kernlog have been removed successfully!\n")

    

elif a==6:

    if os.path.exists('/root/Bk') is True:

        os.system("rm -rf /root/Bk")

    else:

        os.system("mkdir /root/Bk")

        time.sleep(1)

        os.system("zip -r /root/Bk/mysql.zip /var/lib/mysql")

        time.sleep(1)

        os.system("zip -r /root/Bk/blog.zip /var/www/html/testweb/blog")

        time.sleep(1)

        os.system("bypy -v --chunk 512 -s 10MB --on-dup overwrite upload /root/Bk \Bk")

        time.sleep(1)

        os.system("rm -rf /root/Bk")

        print("Done!\n")

    

else:

    print("\nPlease enter the above mentioned number and try again later!")
































Ubuntu 16.04設置開機啟動腳本的方法



rc.local腳本

rc.local腳本是一個ubuntu開機後會自動執行的腳本,我們可以在該腳本內添加命令行指令。該腳本位於/etc/路徑下,需要root權限才能修改。

該腳本具體格式如下:

#!/bin/sh -e## rc.local## This script is executed at the end of each multiuser runlevel.# Make sure that the script will "exit 0" on success or any other# value on error.## In order to enable or disable this script just change the execution# bits.## By default this script does nothing.#/bin/sh /home/saneri/new_service.sh #腳本範例exit 0

註意: 一定要將命令添加在 exit 0之前

方法2:

如何給ubuntu添加一個開機啟動腳本

1,新建個腳本文件new_service.sh

#!/bin/bash# command content# ..................................exit 0

2,設置權限

sudo chmod 755 new_service.sh

3,把腳本放置到啟動目錄下

sudo mv new_service.sh /etc/init.d/

4,將腳本添加到啟動腳本

執行如下指令,在這裏90表明一個優先級,越高表示執行的越晚

cd /etc/init.d/sudo update-rc.d new_service.sh defaults 90




移除Ubuntu開機腳本

sudo update-rc.d -f new_service.sh remove




« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。