Ask Your Question

Revision history [back]

help with shell script for school

Sorry I am very new and this and do not know what I am doing from I am sure the -f should be a different command but since is really my first shell script I am writing just as the professor has requested.

The error I am getting is ./acctchk.sh: line 7: [-f: command not found

Here is the full script copied from the instructions. (any suggestions are welcome I am working in a VM with Fedora 26)

!/bin/sh

acctchk.sh

This script compares the current /etc/passwd file against an archived copy called /root/passed.ar. # It produces a list of added or deleted accounts. It creates an archived file from /etc/passwd

called /root/passwd.ar if none exists.

cd /root if [ -f /root/passwd.ar ] then echo “Today is date” # print today’s date sort </etc> ./tmp2 # sort the contents of the /root/passwd.ar file into tmp2 echo “* Accounts added:” comm -23 ./tmp1 ./tmp2 # output any lines that are in tmp1 but not in tmp2 (added accounts) echo “ Accounts deleted:” comm -13 ./tmp1 ./tmp2 # output any lines that are in tmp2 but not in tmp1 (deleted accounts) echo “” rm –f ./tmp1 ./tmp2 # remove temporary files else echo “* Creating archived /etc/passwd file ** “ cp /etc/passwd /root/passwd.ar # create the archive if it doesn’t already exist fi

help with shell script for school

Sorry I am very new and this and do not know what I am doing from I am sure the -f should be a different command but since is really my first shell script I am writing just as the professor has requested.

The error I am getting is ./acctchk.sh: line 7: [-f: command not found

Here is the full script copied from the instructions. (any suggestions are welcome I am working in a VM with Fedora 26)

!/bin/sh

acctchk.sh

`#!/bin/sh
#  acctchk.sh 
#  This script compares the current /etc/passwd file against an archived copy called /root/passed.ar.  #  It produces a list of added or deleted accounts.  It creates an archived file from /etc/passwd

/etc/passwd # called /root/passwd.ar if none exists.

exists. cd /root if [ -f /root/passwd.ar ] then echo “Today is date`date`” # print today’s date sort </etc> ./tmp2 </etc/passwd > ./tmp1 # sort the contents of the /etc/passwd file into tmp1 sort </root/passwd.ar> ./tmp2 # sort the contents of the /root/passwd.ar file into tmp2 echo * “*** Accounts added:” comm -23 ./tmp1 ./tmp2 # output any lines that are in tmp1 but not in tmp2 (added accounts) echo “*** Accounts deleted:” comm -13 ./tmp1 ./tmp2 # output any lines that are in tmp2 but not in tmp1 (deleted accounts) echo “” rm –f ./tmp1 ./tmp2 # remove temporary files else echo * “** Creating archived /etc/passwd file ** “ cp /etc/passwd /root/passwd.ar # create the archive if it doesn’t already exist fi

fi`
click to hide/show revision 3
retagged

updated 2018-11-04 09:31:06 -0600

hhlp gravatar image

help with shell script for school

Sorry I am very new and this and do not know what I am doing from I am sure the -f should be a different command but since is really my first shell script I am writing just as the professor has requested.

The error I am getting is ./acctchk.sh: line 7: [-f: command not found

Here is the full script copied from the instructions. (any suggestions are welcome I am working in a VM with Fedora 26)

`#!/bin/sh
#  acctchk.sh 
#  This script compares the current /etc/passwd file against an archived copy called /root/passed.ar.  #  It produces a list of added or deleted accounts.  It creates an archived file from /etc/passwd 
#  called /root/passwd.ar if none exists.
cd  /root
if [ -f  /root/passwd.ar ]
then
  echo “Today is `date`”       # print today’s date
  sort </etc/passwd > ./tmp1     # sort the contents of the /etc/passwd file into tmp1
  sort </root/passwd.ar> ./tmp2  # sort the contents of the /root/passwd.ar file into tmp2
  echo “*** Accounts added:”
  comm -23 ./tmp1 ./tmp2    # output any lines that are in tmp1 but not in tmp2 (added accounts)
  echo “*** Accounts deleted:”
  comm -13 ./tmp1 ./tmp2  # output any lines that are in tmp2 but not in tmp1 (deleted accounts)
  echo “”
  rm –f ./tmp1 ./tmp2  # remove temporary files
else
  echo “** Creating archived /etc/passwd file ** “
  cp /etc/passwd  /root/passwd.ar  #  create the archive if it doesn’t already exist
fi`