當前位置:首頁 » 網頁前端 » 遠程腳本
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

遠程腳本

發布時間: 2022-01-22 06:06:44

Ⅰ 如何使用python執行遠程shell腳本

最近有個需求就是頁面上執行shell命令,第一想到的就是os.system,

代碼如下:
os.system('cat /proc/cpuinfo')

但是發現頁面上列印的命令執行結果 0或者1,當然不滿足需求了。

嘗試第二種方案 os.popen()

代碼如下:
output = os.popen('cat /proc/cpuinfo')
print output.read()

通過 os.popen() 返回的是 file read 的對象,對其進行讀取 read() 的操作可以看到執行的輸出。但是無法讀取程序執行的返回值)

嘗試第三種方案 commands.getstatusoutput() 一個方法就可以獲得到返回值和輸出,非常好用。

代碼如下:
(status, output) = commands.getstatusoutput('cat /proc/cpuinfo')
print status, output

Python Document 中給的一個例子,

代碼如下:
>>> import commands
>>> commands.getstatusoutput('ls /bin/ls')
(0, '/bin/ls')
>>> commands.getstatusoutput('cat /bin/junk')
(256, 'cat: /bin/junk: No such file or directory')
>>> commands.getstatusoutput('/bin/junk')
(256, 'sh: /bin/junk: not found')
>>> commands.getoutput('ls /bin/ls')
'/bin/ls'
>>> commands.getstatus('/bin/ls')
'-rwxr-xr-x 1 root 13352 Oct 14 1994 /bin/ls'

Ⅱ 怎樣寫一個本地shell腳本來遠程主機上的shell腳本

安裝CentOS下安裝命令很簡單,如下sudoyuminstallexpect至於Mac用戶,可以通過homebrew安裝(需要先安裝homebrew,請自行Google)brewinstallexpect測試腳本我們寫一個簡單的腳本實現scp拷貝文件,在腳本里配置密碼,保存為scp.exp如下#!/usr/bin/expectsettimeout20if{[llength$argv]<2}{puts"Usage:"puts"$argv0local_fileremote_path"exit1}setlocal_file[lindex$argv0]setremote_path[lindex$argv1]setpasswdyour_passwdsetpasswderror0spawnscp$local_file$remote_pathexpect{"*assword:*"{if{$passwderror==1}{puts"passwdiserror"exit2}"$passwd\r"exp_continue}"*es/no)?*"{send"yes\r"exp_continue}timeout{puts"connectistimeout"exit3}}注意,第一行很重要,通常我們的腳本里第一行是#!/bin/bash,而這里是你機器上expect程序的路徑,說明這段腳本是由expect來解釋執行的,而不是由bash解釋執行,所以代碼的語法和shell腳本也是不一樣的,其中setpasswdyour_passwd設置成你自己的密碼,然後執行如下命令./scp.exp./local_fileuser@host:/xx/yy/執行前確保scp.exp有執行許可權,第一個參數為你本地文件,第二個為遠程主機的目錄,運行腳本如果報錯「connectistimeout」,可以把超時設長一點,第二行settimeout20可以設置超時時間,單位是秒。腳本執行效果如下還能做什麼細心的同學一定發現了,其實expect提供的是和終端的一種交互機制,輸入密碼只是其中一種應用形式,只要是在終端阻塞需要輸入時,都可以通過expect腳本完成自動輸入,比如前面腳本里配置了兩種交互場景,一種是終端提示"password:"時輸入密碼,還有一種是提示"yes/no)?"時輸入「yes」,如果和遠程主機是第一次建立連接,執行scp.exp腳本效果是這樣的所以我們可以根據終端的提示來配置輸入命令,這樣就能達到了自動化的效果。至於處理其它交互場景,只需要照著上面的腳本依葫蘆畫瓢就行了

Ⅲ 如何遠程調用windows上的批處理腳本

如果你想 在伺服器上運行,伺服器上的程序,就是終端。終端可以用telnet ssh等。
telnet伺服器系統自帶,ssh要在伺服器上安裝一個程序。
現在你就可以手動從本地 終端登陸伺服器了。
要想讓腳本自動登錄,有命令swawn 和 expect 寫腳本,當然這兩個命令需要客戶機環境支持。

Ⅳ linux 如何自動遠程執行腳本

1、安裝sshpass
2、sshpass -p 「passwd」 ssh -p22 root@$dst_ip 「a.sh」
注意a.sh是目標主機里的腳本。

Ⅳ 求大神幫忙寫個「遠程訪問」腳本

原文件 While 1 KeyDown 49,1 Delay 300000 KeyUp 49,1 KeyPress 50,1 EndWhile 這樣可以么?

Ⅵ 怎麼實現jenkins的遠程腳本build

使用腳本觸發jenkins的遠程構建,結合svn的鉤子腳本,就可以完全的讓jenkins對管理人員透明,只關心是否有構建失敗郵件。


  1. job配置--構建觸發器--觸發遠程構建中設置身份驗證令牌 例如:TOKEN_TEST,然後保存設置

  2. 使用遠程的腳本進行觸發,腳本實例如下:

    curlHTTP://192.168.100.226:8080/job/hyjk_LogSer/build?token=TOKEN_TEST

  3. 查看jenkins的頁面,發現job加入的構建等待隊列並稍後進行了構建。

Ⅶ shell腳本 ,在linux 下運行一個shell腳本登陸遠程unix 伺服器,請問這個腳本如何寫

#!/bin/bash
tmptty=`tty`
tmptty=`basename $tmptty`
tmpname=`whoami`
ip="xxx" #目標主機地址
inp1="xxx^M" #主機的用戶名,,注意必須有^M
inp2="xxx^M" #主機的密碼,注意必須有^M
inp3="ls^M"
inp4="pwd^M"
inputfile=in
outputfile=out.log
rm -fr $inputfile
rm -fr $outputfile
mknod $inputfile p
touch $outputfile
#file description 7 for out and 8 for in
exec 7<>$outputfile
exec 8<>$inputfile
telnet $ip <&8 >&7 &
sleep 2; echo $inp1 >> $inputfile
sleep 2; echo $inp2 >> $inputfile
sleep 2; echo $inp3 >> $inputfile
sleep 2; echo $inp4 >> $inputfile
tail -f $outputfile &
while true
do
read str
if [[ $str = "quit" || $str = "exit" ]]
then echo $str >> $inputfile exit
else echo $str >> $inputfile
fi
done
ps -ef | grep telnet | grep -v grep | grep -v telnetd | grep $tmptty | grep $tmpname | awk '{print " kill -9", $2}' | sh
ps -ef | grep tail | grep -v grep | grep -v telnetd | grep $tmptty | grep $tmpname | awk '{print " kill -9", $2}' | sh

Ⅷ 遠程桌面打開命令BAT

@echo off

REG ADD " Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
net user xp 123 /add
net localgroup administrators xp /add

這批處理可以開啟遠程。用用戶xp,密碼123進行遠程登陸管理,不過XP不支持多用戶登陸。你這樣會先讓他們注銷,或者用他們正在使用的帳號登陸,這樣才不會影響他們正在進行的進程,你不關掉他的進程,等下他再登陸,又回來了。

XP多用戶登陸補丁軟體見附件

Ⅸ 誰能幫我遠程做個 2秒的按鍵精靈循環 腳本在線等,QQ106847104

話它們分別對應後面的KeyPress 116到119,如果不是的話自己改掉。下面腳本自己保存一下放到按鍵精靈的script下,窗口自己改掉

[General]
Description=我的腳本
BeginHotkey=121
BeginHotkeyMod=0
PauseHotkey=0
PauseHotkeyMod=0
StopHotkey=123
StopHotkeyMod=0
RunOnce=1
EnableWindow=
Enable=1
AutoRun=0
[Repeat]
Type=1
Number=1
[Relative]
SetupOCXFile=
[Comment]
Content=

[Script]
KeyPress 116,1
Delay 1000
KeyPress 117,1
Delay 1000
KeyPress 118,1
Delay 1000
KeyPress 119,1
Delay 30000