From 04143a7e1307979ce0250f6de73d9612cfb95fc7 Mon Sep 17 00:00:00 2001 From: mo khan Date: Tue, 22 Oct 2019 19:37:48 -0600 Subject: write a shell script to send a message to a user on the machine --- EXAM.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'EXAM.md') diff --git a/EXAM.md b/EXAM.md index 210765e..f02f49a 100644 --- a/EXAM.md +++ b/EXAM.md @@ -124,3 +124,25 @@ Some examples of IPC mechanisms are: * socket: A TCP/UDP can be used for streaming data across a network. * UNIX domain socket: Can be used to stream data from one process to another on a host. * Pipes: A program can write to stdout which can be piped into stdin of another process. + + +# Write a shell script that searches the password file for an input name and sends that person a "hello" message. + +`/etc/passwd` format. + +| login | password set | uid | gid | comment | home dir | shell | + + +```sh +#!/bin/sh + +cd "$(dirname "$0")/.." +USER=${1} + +if cat /etc/passwd | cut -d: -f1 | grep -E "^$USER"; then + echo "hello" | write "$USER" +else + echo "I could not find '${USER}'" + exit 1 +fi +``` -- cgit v1.2.3