pscp挂脚本 [英] pscp hanging script

查看:195
本文介绍了pscp挂脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$ error.clear()

$ erroractionpreference ="SilentlyContinue"
$
echo"开始移动文件"

$ movefile = c:\ pscp.exe -pw **** $ oldfile CowBoy@99.99.99.99:/ file /
$
#Echo $ movefile

$ movefile

if(!$?)

{

$ Title ="错误移动文件的文件"

echo" admin," > $ textdoc

echo"无法将文件移动到destiation"
"
echo""无法将文件移动到destiation" >> $ textdoc

电子邮件

}

否则{

if(Test-Path $ textdoc){

  Remove-Item $ textdoc

  }
$ Title =" working"
$
echo" Admin," > $ textdoc

echo"请查找新文件" >> $ textdoc

删除项目$ oldfile

email}

$error.clear()
$erroractionpreference = "SilentlyContinue"
echo "starting to move the file"
$movefile = c:\pscp.exe -pw **** $oldfile CowBoy@99.99.99.99:/file/
# Echo $movefile
$movefile
if (!$?)
{
$Title ="Error Moving file for file"
echo "admin," > $textdoc
echo "Could not move file to destiation"
echo "Could not move file to destiation" >> $textdoc
email
}
Else {
if (Test-Path $textdoc){
  Remove-Item $textdoc
  }
$Title ="worked"
echo "Admin," > $textdoc
echo "Please look in for new file" >> $textdoc
Remove-Item $oldfile
email}

只要它的工作脚本运行正常。 但是说它无法连接它挂起脚本

as long as it work script run fine.  but say it can not connect it hangs the script

$ movefile = c:\ pscp.exe -pw **** $ oldfile CowBoy@99.99.99.99:/ file /

$movefile = c:\pscp.exe -pw **** $oldfile CowBoy@99.99.99.99:/file/

我想要做的是,如果文件无法向管理员发送电子邮件。

What i want to do is if the file can not move email the admin.

推荐答案

您不能使用PowerShell错误来检测外部程序中的错误 - 请改用

You cannot use PowerShell errors to detect errors in external programs - use


LASTEXITCODE。
LASTEXITCODE instead.

此变量与%ERRORLEVEL%

This variable is the same as %ERRORLEVEL%


这篇关于pscp挂脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆