1 // Yet another (tm) fetch program
4 #include <sys/utsname.h>
5 #include <sys/sysinfo.h>
16 char hostname[HOST_NAME_MAX];
17 gethostname(hostname, HOST_NAME_MAX);
20 char username[LOGIN_NAME_MAX];
21 getlogin_r(username, LOGIN_NAME_MAX);
23 // Get assorted system info
28 struct tm *uptime = gmtime(&info.uptime);
33 struct tm *wtime = localtime(&rawtime);
36 struct utsname kernel;
39 /* Get memory info from /proc. Inspired by busybox free.c, which is
41 char buf[60]; // actual lines we expect are ~30 chars or less
42 int counter = 2; // Number of things being scanned for in the file
43 unsigned long total_kb, avail_kb;
45 FILE *fp = fopen("/proc/meminfo", "r");
46 total_kb = avail_kb = 0;
47 while (fgets(buf, sizeof(buf), fp)) {
48 if (sscanf(buf, "MemTotal: %lu %*s\n", &total_kb) == 1)
51 if (sscanf(buf, "MemAvailable: %lu %*s\n", &avail_kb) == 1)
58 printf("%s@%s\n", username, hostname);
59 printf("%d-%02d-%02d %02d:%02d:%02d\n", wtime->tm_year + 1900, wtime->tm_mon,
60 wtime->tm_mday, wtime->tm_hour, wtime->tm_min, wtime->tm_sec);
61 printf("%0.0f/%0.0f MB RAM\n", (total_kb - avail_kb)/1024.0, total_kb/1024.0);
62 printf("%s %s\n", kernel.sysname, kernel.release);
63 printf("Up %02dh %02dm %02ds\n", uptime->tm_hour, uptime->tm_min,
65 printf("%0.0f/%0.0f MB RAM\n", (total_kb - avail_kb)/1024.0, total_kb/1024.0);