summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2019-10-22 19:37:48 -0600
committermo khan <mo.khan@gmail.com>2019-10-22 19:37:48 -0600
commit04143a7e1307979ce0250f6de73d9612cfb95fc7 (patch)
tree838bbcda8f562c8bb967d6cbc33deaa62169ae25
parentdbe02b8de38c17fef21dd7d8dc0e78854e2b361c (diff)
write a shell script to send a message to a user on the machine
-rw-r--r--EXAM.md22
-rwxr-xr-xbin/greet11
2 files changed, 33 insertions, 0 deletions
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
+```
diff --git a/bin/greet b/bin/greet
new file mode 100755
index 0000000..947958e
--- /dev/null
+++ b/bin/greet
@@ -0,0 +1,11 @@
+#!/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