统计所有机器的挂载情况
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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
2019-12-31 string::insert
2019-12-31 string::get_allocator