pushd \\1921681111\sharename\dir1
del file1txtimport javaioInputStream;
import javaioPrintStream;
import orgapachecommonsnettelnetTelnetClient;
/
利用apache net 开源包,使用telnet方式获取AIX主机信息
@version 12
/
public class NetTelnet {
// Telnet对象
private TelnetClient telnet = new TelnetClient();
private InputStream in;
private PrintStream out;
// 提示符。具体请telnet到AIX主机查看
private char prompt = '#';
// telnet端口
private String port;
// 用户
private String user;
// 密码
private String password;
// IP地址
private String ip;
public NetTelnet() {
try {
// AIX主机IP
thisip = "2192431210";
thispassword = "05933663007";
thisuser = "administrator";
thisport = "23";
telnetconnect(ip, IntegerparseInt(port));
Systemoutprintln("开始获取输入流");
in = telnetgetInputStream();
out = new PrintStream(telnetgetOutputStream());
// 登录
/ readUntil("login: ");
write(user);
readUntil("Password: ");
write(password);
readUntil(prompt + " ");/
} catch (Exception e) {
eprintStackTrace();
}
}
/
读取分析结果
@param pattern
@return
/
public String readUntil(String pattern) {
try {
char lastChar = patterncharAt(patternlength() - 1);
StringBuffer sb = new StringBuffer();
char ch = (char) inread();
while (true) {
sbappend(ch);
if (ch == lastChar) {
if (sbtoString()endsWith(pattern)) {
return sbtoString();
}
}
ch = (char) inread();
}
} catch (Exception e) {
eprintStackTrace();
}
return null;
}
/
写
@param value
/
public void write(String value) {
try {
outprintln(value);
outflush();
} catch (Exception e) {
eprintStackTrace();
}
}
/
向目标发送命令字符串
@param command
@return
/
public String sendCommand(String command) {
try {
write(command);// 执行删除的命令 rm -rf
return readUntil(prompt + " ");
} catch (Exception e) {
eprintStackTrace();
}
return null;
}
/
关闭连接
/
public void disconnect() {
try {
telnetdisconnect();
} catch (Exception e) {
eprintStackTrace();
}
}
public static void main(String[] args) {
try {
Systemoutprintln("开始执行telnet");
NetTelnet telnet = new NetTelnet();
// 通过aix的命令“查找主机名称”获取数据
// 命令是 "hostname"
// 不熟悉命令的参考<<AIX网络管理手册>>
Systemoutprintln("开始发送hostname命令");
String result = telnetsendCommand("hostname");
Systemoutprintln("显示结果");
Systemoutprintln(result);
// 最后一定要关闭
telnetdisconnect();
} catch (Exception e) {
eprintStackTrace();
}
}
}declare -i flag 设置flag;
for I in `ls 目录`; do 遍历目录
flag=0 假设0为不存在
for J in `获取数据库文件名列表`; do 遍历数据文件名
if I == J; then 如果存在就跳出循环;
flag=1 设置存在标签
break 跳出内层循环
fi
done
if [ $flag -eq 0 ]; then 如果flag没有改变,那么文件是不存在的;
rm -rf $I 删除文件
fi
done
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)