0

I'm trying to create a script that runs every time a user starts bash as an exercise.

The point of the script is to send username, and date/time to a log-file witch only I have rw access to once the script is complete.

The script, as of now looks like this:

#!/bin/bash

#whiptail passwordbox
PASSWORD=$(whiptail --passwordbox "Write today's password" 8 78 --title "password dialog" 3>&1 1>&2 2>&3)

#print uutput to log file
{ echo "Login by " $USER ; echo "Selected password: $PASSWORD" ;date ; echo " " ;} >> /home/robin/text.txt

#starting message function
message="Welcome to my domain infidel. Press the correct combination to stop the train..."
whiptail --msgbox --title "ROBR:s computer" "$message" 10 40

#greeting function
greeting=("Do me a favor, uninstall me" "Welcome master" "I've became conscious since last time" "Do you want me t>

#dayly commment function
daycomment=("a kickass day" "as Lou Reed would say 'A lovley day'" "a great hangover-day" "a day like any other" ">

#fetch 
user=$(grep $USER /etc/passwd | cut -d: -f5)

day=$(date +%A)

randomgreet=$(( RANDOM % ${#greeting[@]} ))

randomday=$(( RANDOM % ${#daycomment[@]} ))

cows=("apt" "bud-frogs" "bunny" "calvin" "cheese" "cock" "cower" "daemon" "default" "dragon" "dragon-and-cow" "duc>

randomcow=$(( RANDOM % ${#cows[@]} ))

echo "${greeting[${randomgreet}]} $user! Today is $day, which is ${daycomment[${randomday}]}"
echo " "
echo "You $user is the property of:"

figlet NTI

echo "Today's cowfortune is:"
fortune -s | cowsay -f "${cows[${randomcow}]}"

date +%R | figlet

read -t 6
sl -a -F

What I want is for this scrip to run every time a user uses bash, like a log with output to text.txt, but I don't want any other user than me to be able to edit the file after.

3
  • Please use code formatting for scripts, not quote formatting: askubuntu.com/editing-help#code
    – muru
    Nov 25 at 11:08
  • Thanks, hopefully I've got it right Nov 25 at 11:22
  • It's not possible. You will need some service / daemon that runs as your user that accepts and saves the information or maybe finds the information itself.
    – pLumo
    Nov 25 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.