Coding4Days Coding4Days -4 years ago 166
Bash Question

Shell Script-Checking if file exists, creating one, export terminal as log

I've just started learning bash yesterday and I need a little help. I need to make a script that will check if a file exists on co-workers computers and, if it doesn't the, script will make one. I have a general idea for that. The more important help I need is recording or logging the script to an output.txt or something of the sorts. I've seen the script command but it seems to be manual. I need it to record every interaction from the start to end and then export it and exit.

I could probably test if that log exists and then append whatever the script needs to check. I assume to start I could do file="./file" (example) and then do

if [ -e "$file" ]; then whatever.


What I plan to do is make a script that maybe checks if a firewall is on or if the co-workers have some file and then export the result(s) to some dir (mkdir). Pure examples. I really just need assistance on the exporting of the whole terminal input and output. Thanks.

Answer Source

This is very simple script just check the existense of file, if so just move it to yourlocaiton dir.

#!/bin/sh
    if [ -f /etc/cruelworld.txt ] ; then
        echo "File exist and moving it to my dir"
        mv /etc/cruelworld.txt /yourlocation
    fi
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download