LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linux Question - .bash_login, etc (https://www.linuxquestions.org/questions/linux-newbie-8/linux-question-bash_login-etc-4175459840/)

omen679 04-27-2013 11:23 PM

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.

shivaa 04-28-2013 12:16 AM

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

jdkaye 04-28-2013 12:25 AM

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

unSpawn 04-28-2013 05:51 AM

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.

Alucarx85 07-24-2013 02:52 PM

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?

Firerat 07-24-2013 03:05 PM

Quote:

Originally Posted by Alucarx85 (Post 4996098)
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

grail 07-24-2013 07:07 PM

Please raise your own question and possibly link to this one if it is a good reference.
You should not resurrect old questions.

Alucarx85 07-24-2013 08:13 PM

ok I will do that, Although, this is not really "SOLVED" yet

Firerat 07-24-2013 08:20 PM

Quote:

Originally Posted by Alucarx85 (Post 4996261)
ok I will do that, Although, this is not really "SOLVED" yet

That is just their sig you were reading :)

Alucarx85 07-24-2013 09:30 PM

oh lol :D :)


All times are GMT -5. The time now is 04:33 PM.