English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Can you write a script for me that does the following (it will be run with root account always):
Check to see if the first 10 characters of tacos.txt is equal to '1234567890' and if it is, run the command 'ls -a'. It needs to run every time the machine boots up!

can someone make that for me?

2007-09-04 04:55:24 · 2 answers · asked by ScytheTleppo 2 in Computers & Internet Programming & Design

2 answers

It depends on your system how to add it to boot, but here is the script, test it before the real usage. I suggest redirecting the command output to the logfile instead of just printing it.
eg. echo "messages" >> logfile.txt

#!/bin/bash
file="tacos.txt"
cont="`head -n1 $file`"
cont="${cont:0:10}"
lookfor="1234567890"

if [ ! -r "$file" ]; then
echo "Can't read the file: $file"
exit 1
fi

if [ "$cont" == "$lookfor" ]; then
ls -a
fi

exit $?

2007-09-04 05:58:35 · answer #1 · answered by nothinks 2 · 0 0

the joys of linux. You dont get an answer, you get 100 answers of different ways that will all work. :)

head -1 tacos.txt | grep 1234567890 >/dev/null && ls -a

the key being the && which says "if first command is successful then run the second command"

2007-09-04 09:44:15 · answer #2 · answered by Gandalf Parker 7 · 0 0

fedest.com, questions and answers