1 / 33

UNIX UTILITY PACKAGE

UNIX UTILITY PACKAGE. Shell Simulator Added Shell Commands File System Explorer ( LNC ) System Information Process Tree Viewer. What Is Shell ?.

rich
Download Presentation

UNIX UTILITY PACKAGE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UNIX UTILITY PACKAGE • Shell Simulator • Added Shell Commands • File System Explorer ( LNC ) • System Information • Process Tree Viewer

  2. What Is Shell ? Shell provides a protective covering for the kernel . A UNIX shell provides a protective outer covering. To protect the user from the complexity of the kernel, and to protect the kernel from the user, a protective shell is built around the kernel. The user makes requests to a shell, which interprets them, and passes them on to the kernel.

  3. Shell Comparison Most contemporary versions of UNIX provide all three shells • Bourne Shell • C Shell • Korn Shell

  4. Functions Of Shell • Command line interpretation • Program initiation • Input-output redirection • Pipeline connection • Substitution of filenames • Maintenance of variables • Environment control • Shell programming

  5. Our Shell Commands

  6. help The list of implemented shell commands with a description

  7. ls ls - Displays entries in the current working directory -l -Displays the file modes and no of links to the file,owner name, group name, size of the file (in bytes)time stamp and the file name. -a - Displays all entries including hidden files -r - Displays all entries in reverse order -i - Displays all file names with their inodes no -i <path> - Displays the inode no of the file name specified -ss - Displays the file names in sorted order on size types - Displays all file names with their types

  8. Shells Display existing shells in the system by reading and printing /etc/shells

  9. Mount Display all devices and file systems mounted in the system by opening and reading /etc/mtab We use mntent structure and setmntent( )getmntent( )for reading the file

  10. Mount continued FILE *fp; struct mntent *mn; fp=setmntent("/etc/mtab","r"); mn=getmntent(fp); while (mn!= NULL) { printf("%s on %s",mn->mnt_fsname,mn->mnt_dir); printf("type %s (%s)",mn->mnt_type,mn->mnt_opts); mn=getmntent(fp); } endmntent(fp);

  11. Sysconfig Long sysconf ( int name ) Get system limits or run time options We pass macros and get integer Macros can be : _SC_ARG_MAX , _SC_CLK_TCK , _SC_OPEN_MAX , _SC_STREAM_MAX ,…

  12. Cpu We open the file /proc/cpuinfoand simply print it for geeting info about the cpu

  13. sysinfo Using sysinfo structure and Sysinfo system call we get info about processes ,memory ,… int sysinfo(struct sysinfo *info);

  14. Sysinfo continued struct sysinfo { long uptime; /* Seconds since boot */ unsigned long loads[3]; /* 1, 5, 15 min load averages */ unsigned long totalram; /* Total usable main memory size */ unsigned long freeram; /* Available memory size */ unsigned long sharedram; /* Amount of shared memory */ unsigned long bufferram; /* Memory used by buffers */ unsigned long totalswap; /* Total swap space size */ unsigned long freeswap; /* swap space still available */ unsigned short procs; /* Number of current processes */ ….. };

  15. fsblk We want to get file system block size. The whole thing is : struct stat st;stat("/",&st); /* current fs */printf("%d",st.st_blksize);

  16. Am Gives info about you ; with the help of getuid() , getlogin ()

  17. Inode<path> Using stat structure and stat system call we get info about inode of the specified file.. struct stat { dev_t st_dev; /* device */ ino_t st_ino; /* inode */ mode_t st_mode; /* protection */ dev_t st_rdev; /* device type (if inode device) */ off_t st_size; /* total size, in bytes */ unsigned long st_blksize; /* blocksize for I/O */ unsigned long st_blocks; /* allocated blocks*/ time_t st_atime; /* time of last access */ time_t st_mtime; /* time of last modification */ time_t st_ctime; /* time of last change */ };

  18. filesys Using struct statfs and statfs system call we get info about file system. int statfs(const char *path, struct statfs *buf); int fstatfs(int fd, struct statfs *buf);

  19. Filesys continued struct statfs { long f_type;/* type of fs */ long f_bsize; /* opt transfer block size */ long f_blocks; /* total data blocks in fs */ long f_bfree; /* free blocks in fs */ long f_bavail; /* free blocks avail to non-superuser */ long f_files; /* total file nodes in fs */ long f_ffree; /* free file nodes in fs */ fsid_t f_fsid; /* file system id */ long f_namelen; /* maxlength of filenames */ long f_spare[6]; /* spare for later */ };

  20. Who , Who -a Using /etc/passwd and /var/run/utmp and structures utmp and passwd we get logged in users or all users. struct utmp { short ut_type; /* type of login */ pid_t ut_pid; /* pid of login process */ char ut_line[UT_LINESIZE]; /* device name of tty - "/dev/" */ char ut_user[UT_NAMESIZE]; /* user name */ char ut_host[UT_HOSTSIZE]; /* hostname for remote login */ struct timeval ut_tv; /* time entry was made. */ int32_t ut_addr_v6[4]; /* IP address of remote host. */ ….. };

  21. Who –a continued struct passwd { char *pw_name; /* user name */ char *pw_passwd; /* user password */ uid_t pw_uid; /* user id */ gid_t pw_gid; /* group id */ char *pw_gecos; /* real name */ char *pw_dir; /* home directory */ char *pw_shell; /* shell program */ };

  22. Time We get useful info by using tm structure and localtime() , time() system calls struct tm { int tm_sec; /* seconds */ int tm_min; /* minutes */ int tm_hour; /* hours */ int tm_mday; /* day of the month */ int tm_mon; /* month */ int tm_year; /* year */ int tm_wday; /* day of the week */ int tm_yday; /* day in the year */ int tm_isdst; /* daylight saving time */ };

  23. Cd .. Cd\ cd <path> OBVIOUSLY with chdir( ) !

  24. Help,Time,Cd,Shells • Help: About all shell commands that we have implemented • Time : Using tm structure we get time , date , day of week and day in year • Cd : File system traversal. It can handle cd \ and cd .. and cd < path > • Shells : Using /etc/shells , we list existing shells in system

  25. Who , Who –a , mount , inode • Who: Using /var/run/utmp we list logged on users • Who –a: Using /etc/passwd we list all who have account • Mount: Using /etc/mtab we list all mounted filesystems in mount table • Inode < path >: Inode table of file as in stat structure

  26. Filesys , sysinfo , Sysconf , Fsblk • Filesys: Using statfs structure and system call we get info about file system • Sysinfo: Using sysinfo structure and system call we get info about system • Sysconf: Using sysconf() system call we get information about system configuration • Fsblk: File system block size

  27. Ls , types , lnc , cpu , am • Lnc: Is a file systtem explorer • Ls: Has been implemented with –i , -a , -ss , -r , -l flags • Types: All file with their types • Cpu: CPU information • Am : Current user information

  28. Late Night Commander (LNC) • GUI for file system exploration • Ability to operation of files like copy , delete , remove ,… • Uses Curses • Gives information about files and file system • It can have shell capabilities

  29. Curses The curses package is a subroutine library for terminal-independent screen-painting and input-event handling which presents a high-level screen model to the programmer, hiding differences between terminal types and doing automatic optimization of output to change one screen-full of text into another.

  30. Curses In 10 Lines !! WINDOW *windir; initscr(); start_color(); init_pair(1,COLOR_WHITE,COLOR_BLUE); windir=newwin(26,70,3,0); box(windir,ACS_VLINE,ACS_HLINE); wattrset(windir,COLOR_PAIR(1)); mvwprintw(windir,1,1," BE BRIEF “); wrefresh(windir); endwin();

  31. Advantages Of The Project ! 1. Portability 2. Low requirements 3. User friendly 4. All advantages of shells applies here ! 5. All advantages of a file system explorer applies to LNC ! 6. Our added shell commands

  32. Limitataions • Not a complete shell • LNC and big directories • LNC not complete • Colors are not that properly implemented • Dependence on the underlaying shell • Bugs !

  33. THANK YOU !

More Related