Simple BASH script not working?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple BASH script not working?
# 1  
Old 05-13-2009
Simple BASH script not working?

So I need a script that does the following:

If a certain user is logged in

Run `command`

Else

Echo “incorrect user”


This is my first stab...which doesn't work:

#!/bin/bash

Code:
X="user=`ls -l /dev/console | cut -d " " -f 4`"
Y="foobar"

echo $X
echo $Y

if [ $X==$Y ]; then
   echo "no"
else
  `echo yes - run something!`
fi


It always echos yes, as though $X == $Y. Sigh. New to this - unsure of what to do.

Thanks,
double

Last edited by doubleminus; 05-13-2009 at 06:51 PM.. Reason: Poorly written question!
# 2  
Old 05-13-2009
How would you expect the script to run in the absence of a logged in user? Is this script in crontab? Is it a daemon?

What exactly are you trying to do -- not how you've tried to do it.
# 3  
Old 05-13-2009
Jim,

Thanks for the reply. I did a poor job of describing what I was trying to do.

If a certain user is logged in...then I want to run a command. Otherwise, no command.
# 4  
Old 05-13-2009
Code:
#!/bin/ksh

iam="${USER}"
goodUSER='iAmGood'

echo "iam->[${iam}]"
echo "goodUser->[${goodUser}]"

if [ "${iam}" = "${goodUser}" ]; then
   echo 'yes - run something!'
else
   echo 'no'
fi

# 5  
Old 05-13-2009
Why just not put the command on the user's profile, so it would run when the user logs in?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple sftp script not working - Please help

I have the below sftp script to transfer a file from a linux host(source) to another linux host(target). Public key is already set up in target host and I am able to transfer file using sftp from source to target. But not sure why the below script(ftp_script) is not working. Any help in this... (3 Replies)
Discussion started by: Armaan
3 Replies

2. Shell Programming and Scripting

[Solved] Simple script not working- for loop

Hi all, Please guide me writing this script Follwing is the file which I have created, which contains the files to be copied. cat system1-dr.txt /etc/passwd /etc/shadow /etc/group /etc/vfstab /etc/profile /etc/default/init /etc/shells /etc/dfs/dfstab /etc/dfs/sharetab... (11 Replies)
Discussion started by: manalisharmabe
11 Replies

3. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

4. Shell Programming and Scripting

Simple bash script help

Hi to everyone here, I'm a new user and relatively-new linuxer. I'm trying to write a script that checks if every file from a directory is present in a given list and if not, delete it. should be simple. But I think I've done half the work only: this is to create the reference list: for c... (2 Replies)
Discussion started by: dentex
2 Replies

5. Shell Programming and Scripting

simple script to alert if internet not working?

Hi, I am constantly automaticaly downloading a few things on the internet but since my internet connection is unstable, it sometimes wont work. Thing is the internet will appear to be connected, but no website can be accessed and no program can successfully connect to any location. I can fix... (4 Replies)
Discussion started by: fuzzylogic25
4 Replies

6. Shell Programming and Scripting

need a simple bash script

to gather the cpu utilization from a system in 5 minute intervals and direct output to file. I'm new at scripting and while this seems like an easy task I'm confused on where to start. thanks for any help (1 Reply)
Discussion started by: mkeyes001
1 Replies

7. Shell Programming and Scripting

simple cgi script not working

hi all, i have installed simple cgi-script under apache/cgi-bin directory hello.cgi #!/usr/bin/perl print "Content-type: text/html\n\n"; print <<END_HTML; <html> <head></head> <body>Hello, World!</body> </html> END_HTML when i hit the url... (6 Replies)
Discussion started by: raghur77
6 Replies

8. Shell Programming and Scripting

Simple BASH script?

Hi guys, I'm new to the forum so forgive me if I'm sounding ... daft. I currently work in a Tech Support role. Every day we have to generate data by running around 10 .sh scripts. I was thinking instead of having to ./filename 10 times is it possible to right a new script that will run these for... (16 Replies)
Discussion started by: JayC89
16 Replies

9. Shell Programming and Scripting

simple perl script not working

why won't below work? I am trying to see a)sipfile has username of the system. b)it will read the sipfile and do a grep function against the /etc/passwd c)it will save that output to /tmp/result.. but my script is just hanging... #!/usr/bin/perl -w open(SIPFILE, "</tmp/sipfile") ... (4 Replies)
Discussion started by: hankooknara
4 Replies

10. Shell Programming and Scripting

Why this simple script, is not working ?

Hi everybody I want to create 20 file using simple script - listed bellow-. But the script doesn't work. I hope anyone guide me to correct this script ---------------- The script integer number=01 until (($number==21)) do >TELE-LOG-$number number=$number+01 echo $number done exit... (4 Replies)
Discussion started by: so_friendly
4 Replies
Login or Register to Ask a Question