zoukankan      html  css  js  c++  java
  • 统计所有机器的挂载情况

     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

     
  • 相关阅读:
    【深入学习MySQL】MySQL的索引结构为什么使用B+树?
    【Python爬虫】爬了七天七夜,终于爬出了博客园粉丝数排行榜!
    【BAT面试题系列】面试官:你了解乐观锁和悲观锁吗?
    深入学习MySQL事务:ACID特性的实现原理
    深入学习Redis(5):集群
    深入学习Redis(4):哨兵
    谈谈微信支付曝出的漏洞
    深入学习Redis(3):主从复制
    深入学习Redis(2):持久化
    Spring中获取request的几种方法,及其线程安全性分析
  • 原文地址:https://www.cnblogs.com/xpylovely/p/15753508.html
Copyright © 2011-2022 走看看