1.wps表格 数据-》自动筛选和重复项,找到新旧板卡的IP地址,由于老板卡没有密码
2.在linux中赋值粘贴的txt成doc格式导致程序运行不起来,使用下面命令更改
DOS转UNIX:$ sed -i 's/\r//' dosfile2unixfile.txt
UNIX转DOS:$ sed -i 's/$/\r/' unixfile2dosfile.txt2
3.编写shell登录telnet,并执行df -h,保存到本地ip.txt
#!/bin/bash
file="ip.txt"
while read line
do \
(sleep 1; echo "root"; \
sleep 1; echo "root"; \
sleep 1; echo "df -h"; \
sleep 1;
)| telnet $line > $line.txt
done < $file
----------------------------------------
#!/bin/bash
file="old.txt"
while read line
do \
(sleep 1; echo "root"; \
sleep 1; echo ""; \
sleep 1; echo "df -h"; \
sleep 1;
)| telnet $line > $line.txt
done < $file
4.查看当前文件夹有多少文件
ls .|wc -w
5.编写c程序统计挂载到203.44的IP地址
#include <iostream>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
void check_if_20344(char *file) {
FILE *fp = fopen(file, "r");
char str[1024] = {0};
while(fscanf(fp, "%s\n", str) > 0) {
if (strstr(str, "10.82.203.44")) {
FILE *fp1 = fopen("result.txt", "a+");
fwrite(file, 1, strlen(file), fp1);
fwrite("\n", 1, 1, fp1);
fclose(fp1);
printf("%s mount is 203.44\n", file);
}
memset(str, 0, sizeof(str));
}
fclose(fp);
}
void List(char *path)
{
printf("路径为[%s]\n", path);
struct dirent* ent = NULL;
DIR *pDir;
pDir=opendir(path);
//d_reclen:16表示子目录或以.开头的隐藏文件,24表示普通文本文件,28为二进制文件,还有其他……
while (NULL != (ent=readdir(pDir)))
{
printf("reclen=%d type=%d\t", ent->d_reclen, ent->d_type);
if (ent->d_reclen==24)
{
//d_type:4表示为目录,8表示为文件
if (ent->d_type==8)
{
printf("普通文件[%s]\n", ent->d_name);
}
if (ent->d_type==4)
{
printf("目录[%s]\n", ent->d_name);
}
}
else if(ent->d_reclen==16)
{
printf("[.]开头的子目录或隐藏文件[%s]\n",ent->d_name);
}
else
{
printf("其他文件[%s]\n", ent->d_name);
if (strcmp(ent->d_name, "a.out") == 0 || \
strcmp(ent->d_name, "ip.txt") == 0 || \
strcmp(ent->d_name, "telnet.sh") == 0 || \
strcmp(ent->d_name, "telnet2.sh") == 0 || \
strcmp(ent->d_name, "result.txt") == 0 || \
strcmp(ent->d_name, "tongji.cpp") == 0 || \
strcmp(ent->d_name, "old.txt") == 0)
continue;
check_if_20344(ent->d_name);
}
}
}
int main(){
List(".");
}
6.结果
10.82.1.11.txt
10.82.88.11.txt
10.82.15.240.txt
10.82.15.2.txt