LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-27-2013, 11:23 PM   #1
omen679
LQ Newbie
 
Registered: Apr 2013
Posts: 1

Rep: Reputation: Disabled
Linux Question - .bash_login, etc


Hi Guys,
I am currently taking a linux class and i am completely stuck. Will anyone please help me do this question?

For your final project, you will be demonstrating several concepts that you have learned so far through this course. Recall that whenever you log in, your shell executes commands that it finds in your dotfiles, specifically .bash_login. In your .bash_login, add a series of commands that will first create a directory named ~/sysadmin1/my_peeps/$DATE, where $DATE is today's date in the format mmddyy. This command should succeed whether or not the directory ~/sysadmin1/my_peeps already exists. Then, it will redirect the output of the w command (which lists the currently logged in users on the system) to a file inside this newly created directory called users.$TIME, where $TIME is the current time in the format hhmmss (use 24 hour time).

In order to do this, you must use a new concept: assignment of a variable from the output of a command. For example, in order to set the variable UNDATE using the unformatted output of the date command, you would do the following:

UNDATE=`date`

The characters surrounding the date command are called "backticks." They are usually located on the same key as ~. They are not single quotation marks. This is actually another kind of expansion called "Command Substitution" (you can learn more in bash's manpage).

For this project, you can use the date command to get both the date and the current time, however, you will have to consult date's manpage to find out how to change the formatting.

You can test your additions to .bash_login by logging out and logging back in.
 
Old 04-28-2013, 12:16 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
You have mentioned everything, so where (at which point) you're stuck?

All you need to append few lines in your ~/.bashrc or ~/.profile files.

To create a directory which has name in date (yymmdd) format:
Code:
mkdir -p ~/sysadmin1/my_peeps/$(date +%Y%m%d)
Create a file in time format:
Code:
touch ~/sysadmin1/my_peeps/$(date +%Y%m%d)/$(date +%H%M%S)
To redirect output of w cmd to a file:
Code:
w > ~/sysadmin1/my_peeps/$(date +%Y%m%d)/$(date +%H%M%S)
To store output of the command in any variable:
Code:
VARIABLE_NAME=$(command)
You can also follow this guides:
http://tldp.org/guides.html
http://mywiki.wooledge.org/BashSheet
http://mywiki.wooledge.org/BashGuide

Last edited by shivaa; 04-28-2013 at 01:23 AM.
 
1 members found this post helpful.
Old 04-28-2013, 12:25 AM   #3
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Hi Omen,
I think you can find your answers in this manual: Advanced Bash-Scripting Guide For example on page 10 you find this:
Quote:
The `command` construct makes available the output of command for
assignment to a variable. This is also known as backquotes or backticks.
It's got a huge table of contents so I'm sure you'll find what you need there.
Have fun,
jdk
 
Old 04-28-2013, 05:51 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
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 07-24-2013, 02:52 PM   #5
Alucarx85
LQ Newbie
 
Registered: Jul 2013
Posts: 6

Rep: Reputation: Disabled
Im currently taking linux admin classes on my local community college and I have something very similar like this, actually almost the same problem. I tried to find answers on Google and this is the closest one I found (LQ)

$> mkdir -p ~/folder1/$DATE$(date +%Y%m%d) ; w > ~/folder1/$DATE$(date +%Y%m%d)/users.$TIME$(date +%H%M%S)

$> MY_DATE:`date`

I think you have to designate $TIME, $DATE before doing anything on VI, I'm still a little confused about this. maybe create DATE and TIME first? mkdir?

Last edited by Alucarx85; 07-24-2013 at 02:58 PM.
 
Old 07-24-2013, 03:05 PM   #6
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
Originally Posted by Alucarx85 View Post
Im currently taking linux admin classes on my local community college and I have something very similar like this, actually almost the same problem. I tried to find answers on Google and this is the closest one I found (LQ)

$> mkdir -p ~/test2/$DATE$(date +%Y%m%d) ; w > ~/test2/$DATE$(date +%Y%m%d)/users.$TIME$(date +%H%M%S)

$> MY_DATE:`date`

I think you have to designate $TIME, $DATE before doing anything on VI, I'm still a little confused about this. maybe create DATE and TIME first? mkdir?
Code:
echo mkdir -p ~/test2/$DATE$(date +%Y%m%d)
echo ~/test2/$DATE$(date +%Y%m%d)/users.$TIME$(date +%H%M%S)
Just using echo so I can see what is going on without having to clean up,. cos I is lazy.

it works, but could 'fail'

Code:
DATE=$(date +%Y%m%d)
TIME=$(date +%H%M%S)
and repeat to see why
 
Old 07-24-2013, 07:07 PM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,496

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
Please raise your own question and possibly link to this one if it is a good reference.
You should not resurrect old questions.
 
Old 07-24-2013, 08:13 PM   #8
Alucarx85
LQ Newbie
 
Registered: Jul 2013
Posts: 6

Rep: Reputation: Disabled
ok I will do that, Although, this is not really "SOLVED" yet

Last edited by Alucarx85; 07-24-2013 at 08:15 PM.
 
Old 07-24-2013, 08:20 PM   #9
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
Originally Posted by Alucarx85 View Post
ok I will do that, Although, this is not really "SOLVED" yet
That is just their sig you were reading
 
Old 07-24-2013, 09:30 PM   #10
Alucarx85
LQ Newbie
 
Registered: Jul 2013
Posts: 6

Rep: Reputation: Disabled
oh lol
 
  


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
linux distro question & mysql install question natalie.aloi Linux - Newbie 5 07-19-2009 08:28 PM
.~/bash_login No such file or directory psylovibe Linux - Newbie 3 04-07-2009 02:04 AM
.bash_login .bash_logout on KDE and GNOME ja_nch Linux - General 3 10-09-2003 09:09 PM


All times are GMT -5. The time now is 04:14 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