中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » 其它操作系统综合讨论区 » 批量更改远程服务器的计划任务执行的密码
作者:
标题: 批量更改远程服务器的计划任务执行的密码 上一主题 | 下一主题
maker0321
初级用户




积分 78
发帖 37
注册 2007-11-5
状态 离线
『楼 主』:  批量更改远程服务器的计划任务执行的密码

由于公司考虑到安全问题,总是时隔一个月左右就要更改近100台服务器上的用户名和密码,但是一旦更改密码以后,原先利用这些用户做的计划任务就不能执行了。(小弟在一家电子商务公司做运维,所以才会维护这么多服务器。)以前每次都是远程连接上服务器上更改,但是这样重复性的工作太烦躁。所以想了以下的方法,希望能抛砖引玉,得到高手们的更为简便的方法。小弟在这里先谢过大家。
准备条件:
开启所有服务器的一个共享文件,要求共享权限为写入【这是最为繁琐的事情了,但是这次麻烦一次,下次就不需要再做了。】
在一台服务器上准备以下脚本即可。Password.bat、task.bat和一个server.txt的文件,其中记录所有需要更改服务器的ip地址,每行一个ip格式即可。
目的:
这样可以做到只要在一台服务器(A)上就可以更改所有服务器的用户密码及计划任务执行用户的密码

Password.bat脚本内容
net user maker0321 1q2w3e!@# 【更改用户的密码。可以多些几行来更改多个用户】
Schtasks /change /tn "viruscheck"【计划任务的名称】 /ru:maker0321【更改的用户】 /rp "1q2w3e!@#"【更改的密码】
【更改计划任务执行用户的密码,可以多些几行来更改多个计划执行用户密码】

Server.txt脚本内容:记录所有服务器的ip地址,每行一个ip格式
1.1.1.1
1.1.1.2
…………
…………

Task.bat脚本内容
@echo off
for /f "delims=" %%a in (d:\server.txt)【server.txt文件位置】 do (copy /y d:\password.bat \\%%a\d
at  \\%%a 12:00 \\%%a\d\password.bat)
执行的操作:
1、        拷贝本地服务器的password.bat脚本到所有服务器上的d盘上(需要事先开启所有服务器的D盘)
2、        在所有服务器上创建计划任务,内容就是password.bat的内容

只要在服务器A上双击task.bat文件就可以更改所有服务器的密码及计划任务的密码了。
过程就是这样了。希望高手们指点更为简便的方法。谢谢~~

2008-3-31 13:06
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
Climbing
铂金会员

网络独行侠


积分 6962
发帖 2753
注册 2003-4-16
来自 河北保定
状态 离线
『第 2 楼』:  

为什么不让所有的服务器共享同一个目录下的password.bat呢?

你在其中一台服务器上建立一个共享,将password.bat放到这个服务器上,而其它的服务器都共享这台服务器上的这个password.bat,这样你只需要更改一次password.bat就可以了。



偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
2008-3-31 16:15
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (653668)  编辑帖子  回复  引用回复
maker0321
初级用户




积分 78
发帖 37
注册 2007-11-5
状态 离线
『第 3 楼』:  



  Quote:
Originally posted by Climbing at 2008-3-31 04:15 PM:
为什么不让所有的服务器共享同一个目录下的password.bat呢?

你在其中一台服务器上建立一个共享,将password.bat放到这个服务器上,而其它的服务器都 ...

这个我也试过了。可以到了对方的服务器怎么都执行不了。不知道为什么

2008-3-31 18:38
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
dato
高级用户




积分 916
发帖 377
注册 2004-3-8
状态 离线
『第 4 楼』:  

既然都开共享了那不如使用microsoft.com的psexec

http://www.microsoft.com/technet/sysinternals/default.mspx

psexec远程执行,它太方便高效了,一切都是鼠标轻轻一点



http://dato.ys168.com
google search bot
http://dato.minidns.net/
2008-3-31 22:21
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
Climbing
铂金会员

网络独行侠


积分 6962
发帖 2753
注册 2003-4-16
来自 河北保定
状态 离线
『第 5 楼』:  



  Quote:
Originally posted by maker0321 at 2008-3-31 18:38:


这个我也试过了。可以到了对方的服务器怎么都执行不了。不知道为什么

因为你是直接用这种形式执行的:\\server\share\password.bat

而cmd是不支持UNC路径作为当前目录的,所以你要么:
net use x: \\server\share
start /wait x:\password.bat
net use x: /d

要么:
copy \\server\share\password.bat %tmp%\password.bat
start /wait %tmp%\password.bat
del /f /q %tmp%\password.bat

两种方式任选其一即可。



偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
2008-4-1 01:11
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (653668)  编辑帖子  回复  引用回复
maker0321
初级用户




积分 78
发帖 37
注册 2007-11-5
状态 离线
『第 6 楼』:  

还是没有明白Climbing的意思。2种方法是不是都要做成批处理上传到其他服务器来执行?
能不能让其他服务器通过网络来执行服务器A的事先做好的脚本呢?
我在其他服务器通过网络路径来执行服务器A的批处理文件,都要弹出一个交互界面,要点击确定才可以执行。我想这可能是远程服务器不能执行服务器A的脚本的原因吧

2008-4-2 22:31
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
Climbing
铂金会员

网络独行侠


积分 6962
发帖 2753
注册 2003-4-16
来自 河北保定
状态 离线
『第 7 楼』:  

原因我已经解释过了,你自己对照着解决一次。

   此帖被 +2 点积分    点击查看详情   
评分人:【 maker0321 分数: +2  时间:2008-4-3 14:08




偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
2008-4-3 08:41
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (653668)  编辑帖子  回复  引用回复
maker0321
初级用户




积分 78
发帖 37
注册 2007-11-5
状态 离线
『第 8 楼』:  

Climbing:按照你在二楼的回复。在服务器A上做好一个脚本,共享出来。让其他的服务器来通过共享执行这个脚本。
关键是怎么让其他的服务器来执行这个脚本?是否按照你在5楼的回复?
那按照net use 或者copy,这些命令都是要在其他服务器上执行的。如果我有50台服务器,是不是要在50台服务器上分别执行一下?我想的是能否所有的操作都在服务器A上来执行呢。前提条件已经具备了(所有的服务器用户名和密码相同,但是都不开放默认共享)。如果Climbing觉得问题实在是太弱智了。那可以结贴了。

2008-4-3 11:12
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
dato
高级用户




积分 916
发帖 377
注册 2004-3-8
状态 离线
『第 9 楼』:  

为什么psexec这么好用的工具不用,也许不能满足你的要求吧,它需要
What are the minimum requirements to run PSTools commands
On your target machine check if
it is not running Windows XP Home. Windows XP Home is lacking some of the network functionality required by (most) PSTools commands
(Jerome, I read that you are using WinXP Pro Sp2, so this is not for you, but others reading this.)

the Workstation service is running (check using services.msc)

the Server service is running (check using services.msc)

the Admin$ share is available (check using computer management)

the Windows Network is running and Printer and File Sharing are activated (no need to actually share anything)

Incomming network users authenticate as themselves
To achieve this:
(1) Turn off simple file sharing and thus turn on classical file sharing like on Win2K.
(2) Turn of network users identify as guests and thus turn on network users identify as themselves like on Win2K.
(Please, read how to configure authentication here.)


Note:
Classical Network Authentication requires a non-empty password.
If you have not already done so, assign the user who will logon to \\target a strong password.
(This is recommended for security reasons anyway.)
(Again, Jerome, this is not for you, read your statement about the complex password.)

Check your WinXP firewall settings. By default on WinXP Sp2 the firewall will block any incoming traffice. So it may be necessary to open ports 135 and 445 on your target machine for incoming traffic from your local machine.


As soon as your target machine meets all of the above listed requirements, from your local machine try to execute these commands to your target machine:

net use \\target\Admin$ /user:Administrator
dir \\target\Admin$
net use \\target\Admin$ /delete (only disconnects, does not delete anything.)

If these 3 commands work, then it should be possible to run psexec to \\target as well.



以下是个简单的范例

更改学生端密码.cmd
-----------------------------
for /f "tokens=1,2 delims=/ " %%a in (password.txt) do @psexec \\%%a -u administrator -p onlyedu –c -d run.cmd %%b
-----------------------------

Run.cmd
--------------------------------
net user onlyit "%1"
%windir%\System32\rundll32.exe user32.dll,LockWorkStation
----------------------------------

Password.txt
------------------------------
192.168.1.3/123456
192.168.1.8/fsdaf
-------------------------------

   此帖被 +2 点积分    点击查看详情   
评分人:【 maker0321 分数: +2  时间:2008-4-3 14:08




http://dato.ys168.com
google search bot
http://dato.minidns.net/
2008-4-3 12:23
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
maker0321
初级用户




积分 78
发帖 37
注册 2007-11-5
状态 离线
『第 10 楼』:  

谢谢dato。稍后测试psexec。

2008-4-3 14:15
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: