I wrote a small C program (a long ago), Personally, i use it and thought to share it with you
Code: Select all
/* sysinfo
*-----*
25122003 - 120531
LICENSE: GPL
NAME
sysinfo - print some user\system information
SYNOPSIS
sysinfo
DESCRIPTION
Show system information:
1- $USER,$UID,$GID,$HOME,$SHELL,$GECOS.
2- uptime (hours,minutes,seconds)
3- load averagr (1,5 and 15 minutes)
4- RAM (total,free and shared)
5- Memory in buffers
6- swap (total,used and free)
7- procs
AUTHOR
Written by Nizar Abed - nizar_AT_srcget.com
REPORTING BUGS
Report bugs to <nizar\ AT\ srcget.com>
COPYRIGHT
Copyright (c) 2003,2004 Nizar Abed.
This is free software; see the source for copying conditions. There is
NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <linux/unistd.h>
#include <linux/kernel.h>
#include <sys/sysinfo.h>
#include <unistd.h>
#include <string.h>
#include <pwd.h>
#include <grp.h>
#include <utmp.h>
#include <time.h>
#include <sys/times.h>
/* some colors */
#define REDF "\033[31m"
#define REDB "\E[41m"
#define GREENF "\033[32m"
#define GREENB "\E[42m"
#define RSTF "\033[0m"
#define RESETB "\E[0m"
#define BOLD "\033[1m"
/* Version */
#define VERSION "0.2"
void CLS();
int main(int argc, char *argv[])
{
CLS();
struct sysinfo sinf;
if( sysinfo(&sinf) != 0 )
exit( EXIT_FAILURE );
printf("\033[01;31msysinfo - %s\nLicense: GPL\033[00m\n\n",VERSION);
struct passwd *user;
uid_t uid = getuid();
if( (user = getpwuid(uid)) == NULL )
exit(EXIT_FAILURE);
printf("$USER:%s%s%s\t",GREENF,user->pw_name,RSTF);
printf("$UID:%s%d%s\t",GREENF,user->pw_uid,RSTF);
printf("$GID:%s%d%s\t",GREENF,user->pw_gid,RSTF);
printf("$HOME:%s%s%s\n",GREENF,user->pw_dir,RSTF);
printf("$SHELL:%s%s%s\n",GREENF,user->pw_shell,RSTF);
printf("$GECOS:%s%s%s\n\n",GREENF,*(user->pw_gecos)!='\0'?user->pw_gecos : "gecos EMPTY",RSTF);
// uptime in seconds:
// uptime / 86400 == days
// ( uptime - (days * 86400) ) / 3600 == hours
// ( uptime - (hours * 3600) ) / 60 == minutes
// uptime - (days * 86400) - (hours * 3600) - (minutes * 60) == seconds
// :)
int days = sinf.uptime / 86400;
int hours = ( sinf.uptime - (days * 86400 ) ) / 3600;
int minutes = ( sinf.uptime - (days * 86400) - (hours * 3600) ) / 60 ;
int seconds = sinf.uptime - (days * 86400) - (hours * 3600) - (minutes * 60);
printf("Uptime:\n");
printf("%s%.3d DAYS%s\n",GREENF,days,RSTF);
printf("%s%.3d HOURS%s\n",GREENF,hours,RSTF);
printf("%s%.3d MINUTES%s\n",GREENF,minutes,RSTF);
printf("%s%.3d SECONDS%s\n\n",GREENF,seconds,RSTF);
printf("Load:\n");
printf("%s[1 min] %.8d\n",GREENF,sinf.loads[0]);
printf("[5 min] %.8d\n",sinf.loads[1]);
printf("[15 min] %.8d%s\n\n",sinf.loads[2],RSTF);
int usedram = sinf.totalram - sinf.freeram;
printf("RAM:\n");
printf("%s\tTotal\t:\t%d Bytes / %.2f MB\n",
GREENF,sinf.totalram ,float(sinf.totalram / 1048576));
printf("\tUsed\t:\t%d Bytes / %.2f MB / %.2f%\n",
usedram, float(usedram / 1048576),
(float(usedram) / sinf.totalram) * 100);
printf("\tFree\t:\t%d Bytes / %.2f MB / %.2f%\n",
sinf.freeram,float(sinf.freeram / 1048576),
(float(sinf.freeram) / sinf.totalram) * 100);
printf("\tShared\t:\t%d Bytes / %.2f MB%s\n\n",
sinf.sharedram,float(sinf.sharedram / 1048576),RSTF);
int usedswap = sinf.totalswap - sinf.freeswap;
printf("Memory in buffers:%s\n\t%d Bytes / %.2f MB%s\n\n",
GREENF,sinf.bufferram,float(sinf.bufferram / 1048576),RSTF);
printf("Swap:\n");
printf("%s\tTotal\t:\t%d Bytes / %.2f MB\n",
GREENF,sinf.totalswap,float(sinf.totalswap / 1048576));
printf("\tUsed\t:\t%d Bytes / %.2f MB / %.2f%\n",
usedswap,float( usedswap / 1048576 ),
(float(usedswap) / sinf.totalswap) * 100);
printf("\tFree\t:\t%d Bytes / %.2f MB / %.2f%\n\n%s",
sinf.freeswap,float( sinf.freeswap / 1048576 ),
(float(sinf.freeswap) / sinf.totalswap) * 100,RSTF);
printf("procs: %s%d%s\n\n",GREENF,sinf.procs,RSTF);
return EXIT_SUCCESS;
}
/*----------------------*/
/* clear screen */
void CLS() {
printf("\033[2J\033[0;0H");
}





