Score:0

How can I save bash output to a file witch only I can write to?

ph flag

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.

muru avatar
us flag
Please use code formatting for scripts, not quote formatting: https://askubuntu.com/editing-help#code
Robin Bräck avatar
ph flag
Thanks, hopefully I've got it right
pLumo avatar
in flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.