2013-07-20 158 views
3

我有一個.ps1 powershell腳本,它在窗口中執行,但我的整個數據都在linux服務器上,有沒有任何可能的方式可以通過我執行紅帽服務器PowerShell腳本我想在紅帽linux服務器執行.ps1 powershell腳本

PowerShell腳本是:

Clear-Host 
$path="D:\Deep Backup 26-04-2013\New folder" 
$systemname=Read-Host 'Enter System Name' 



$files=Get-ChildItem $path -Recurse -Force -Include *_Registrar.zip*,*.reg.zip* 


$counter=1 

foreach($file in $files) 
{ 
    $name=$file.name 
    [void][system.reflection.Assembly]::LoadFrom("C:\Program Files\MySQL\MySQL Connector Net 6.5.4\Assemblies\v2.0\MySql.Data.dll") 
    $dbconnect=New-Object MySql.Data.MySqlClient.MySqlConnection 
    $dbconnect.ConnectionString="server=localhost;userid=root;password=nPr123*;database=test3;" 
    $dbconnect.Open() 

    $sql="insert into eid values('"+$name + "','"+$systemname+"')" 


    $command=new-object MySql.Data.MySqlClient.MySqlCommand($sql,$dbconnect) 
    $command.ExecuteNonQuery() 


} 
$sql="insert into eid_unique 
     select distinct Packet_name, System_name from eid a 
     where not exists (select 1 from eid_unique b 
     where a.Packet_name=b.Packet_name);" 


    $command=new-object MySql.Data.MySqlClient.MySqlCommand($sql,$dbconnect) 
    $command.ExecuteNonQuery() 
$dbconnect.close() 
+2

你最好在bash/ruby​​/python/perl中實現它。 –

+0

即使在回答中提到的「Pash」也沒有辦法可以加載.NET dll(在你的例子中它是MySql.Data.dll)......因爲Andy Arismendi提到你需要重新實現腳本到其他腳本語言 –

+0

我第二個堅持使用平臺「本地」語言的建議。 –

回答

0

這聽起來像Pash可以爲你工作。

+0

有趣,但它看起來並不像它正在積極保持。 –

3

Pash是一個正在開發中的Powershell的跨平臺單聲道克隆。 您只需要下載,使用xbuild構建它,然後運行它。 就像使用PowerShell在Windows中可以用執行腳本

& '/path/to/script.ps1' 
2

四年後從原來的問題微軟發佈的PowerShell對於Linux。而且它的開源:https://github.com/PowerShell/PowerShell

在Linux環境下,你可以使用語法如下:(script.ps1,可執行文件)

#!/usr/bin/powershell -Command 

write-host -fore Green "executing PowerShell!"; 
相關問題