LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-21-2010, 01:48 AM   #1
m4manoze
LQ Newbie
 
Registered: Feb 2010
Posts: 11

Rep: Reputation: 0
regarding bash script


Dear Experts,

I want to create user information after querying file called "STORE_FILE". In STORE_FILE i had the information of total email users with expiry date.
Like:
[root@mail home]vi STORE_FILE
###USERID:EXPIRYDATE
xyz@abc.com.np:2011-01-10
mno@abc.com.np:2011-05-11
and so on..........

now i want to create a bash script by which it will show the expiry date of particular user. And also want script to add, edit, view and del unwanted userid from the file STORE_FILE.

Please any help will be appreciated.

Thank you!!!

Regards,
Manoj
 
Old 02-21-2010, 02:14 AM   #2
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Rep: Reputation: 37
Are you looking for someone to do your homework?
 
Old 02-21-2010, 03:50 AM   #3
BeacoN
Member
 
Registered: Nov 2008
Distribution: Linux Mint
Posts: 56

Rep: Reputation: 17
commands

some commands to research...

use 'grep' tp search for something

use 'sed' to delete lines (matching what you want)

use 'echo' to insert something

check out the man pages and come back if you have specific questions. No we will not create this for you. Show some initiative.
 
Old 02-21-2010, 03:59 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.
 
Old 02-21-2010, 11:02 PM   #5
m4manoze
LQ Newbie
 
Registered: Feb 2010
Posts: 11

Original Poster
Rep: Reputation: 0
here is what i have tried

Dear ALL,

I have tried like this:

i have just started the code with bash and for now i am stucked in if else condition. for the 1st function1 i have asked user to input the user name and then with grep command i have search the input username and append to tmp file and then i count the line of tmp file. now temp file has two conditions, either 1 or 0 so with this i want to assign a values present on t file. whatever value present on t file will assign to value.
Now i have used if condition for jumping 2 statement. but when i run the script it only jump to one condition, what ever value present on t file.

Please suggest what to do?? I think i am going wrong way....but this is all what i know......sorry....


*********************************************************************

[root@mail bashtest]# ls
database t test1 tmp


**********************************************************************
[root@mail bashtest]vi test1
###USERID:EXPIRYDATE
xyz@abc.com.np:2011-01-10
mno@abc.com.np:2011-05-11
and so on.........

*********************************************************************

#!/bin/bash

function function1
{
echo -e "Enter Username:\c "
read user1
x=$user1
#echo $x
grep $user1 ./database > tmp
wc -l tmp | awk '{print $1}' > t
value="$/home/manoj/bashtest/t"
if [ $value -eq 1 ];
then
echo "User $user1 already exist in database"
else
echo "not in database"
# echo $user1':'>> "/home/manoj/bashtest/database"
# echo -e "Enter Expire date:\c"
# read date1
# echo $date1 >> "/home/manoj/bashtest/database"
# }
fi

}

echo "PLEASE ENTER:"
echo "1. Add User In Expire file:"
echo "2. Delet User From Expire file:"
echo "3. Show User Expire:"
echo "4. Edit User in Expire:"
read case;

case $case in
1) function1
#2) echo "2";;
#3) echo "3";;
#4) echo "4";;

esac

**********************************************************************
 
Old 02-21-2010, 11:27 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
After value="$/home/manoj/bashtest/t", add
Code:
echo "DEBUG: \$value is '$value'"
ALternatively you can trace what the script is doing by putting set -xv before the commands you want to trace (and set +xv to turn it off).

It's easier to read your code if you put it in code tags (that's a link to instructions or you may prefer to use "Advanced Edit" mode which has a # button for code tags).

It's helpful if you also post the output from running the script.
 
Old 02-22-2010, 12:03 AM   #7
m4manoze
LQ Newbie
 
Registered: Feb 2010
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by catkin View Post
After value="$/home/manoj/bashtest/t", add
Code:
echo "DEBUG: \$value is '$value'"
ALternatively you can trace what the script is doing by putting set -xv before the commands you want to trace (and set +xv to turn it off).

It's easier to read your code if you put it in code tags (that's a link to instructions or you may prefer to use "Advanced Edit" mode which has a # button for code tags).

It's helpful if you also post the output from running the script.


I Get the following output after adding echo "DEBUG: \$value is '$value'"

*********************************************************************

[root@propel bashtest]# sh test1
PLEASE ENTER:
1. Add User In Expire file:
2. Delet User From Expire file:
3. Show User Expire:
4. Edit User in Expire:
1
Enter Username:manoj
DEBUG: $value is '$/home/manoj/bashtest/t'
test1: line 13: [: $/home/manoj/bashtest/t: integer expression expected
not in database
[root@propel bashtest]#

********************************************************************
 
Old 02-22-2010, 01:46 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Exactly what catkin was hinting to you; look at that output and THINK about why you don't get what you expect.
The 'set -vx' stuff is good advice.
I also recommend you bookmark & read these:

http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 05:11 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 12:10 PM
[SOLVED] bash : getopts problem in bash script. angel115 Programming 2 03-02-2009 11:53 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 07:00 AM
Bash script to create bash script jag7720 Programming 10 09-10-2007 08:01 PM


All times are GMT -5. The time now is 04:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration