You are not logged in.

#1 2013-04-02 20:36:18

Apple
Member
Registered: 2013-03-30
Posts: 25

Adding lines of users TODO to motd

Hello,
I've been trying to customise radu242's /etc/issue from the thread https://bbs.archlinux.org/viewtopic.php?id=50845&p=3 into a user specific motd by replacing the text in the box with some lines from the users TODO.txt.

At the moment I have a working, but not really, version that a) doesn't actually use the motd, but echo's the message from /etc/profile,  b) relies on the user keeping their TODO in a specific place, and c) has very ugly bash coding because I'm only learning.

So, in order to finish this, I need more info and was hoping someone could help:

For a)
    Is there any way to call variables directly from the /etc/motd file? - I tried $HOME but that didn't work as I expect it hasn't been initialised by then.

For b)
    I'd like to export a TODO variable before I call the message, which would have to be done very early so it's available in /etc/profile (or motd, if possible). Is there a way of adding an option into the /etc/passwd parsing? I doubt it but it would be awesome if there was, also I'd really appreciate a method of automatically updating (preferably with confirmation from the user) such an option.

For c)
    My TODO's have a specific format, the titles start at the beginning of a line and end with a  :  then the next line is the most important task in that title. In order to put these lines into my logo I need (unless anyone knows a better way) to make the titles and first line underneath into separate variables. I've done this with:

 12 TODOfile="$HOME/TODO/MainTODO.txt"
 13 linenos=$( grep -n -P "^[A-Z].*:$" ${TODOfile} | sed 's/:.*//' )
 14 i=0
 15 
 16 for num in $linenos;
 17 do
 18     newline=$( sed -n "${num}p" ${TODOfile} )
 19     ret[${i}]="${newline}"
 20     i=$(( i+1 ))
 21     num=$(( num+1 ))
 22     newline=$( sed -n "${num}p" ${TODOfile} )
 23     ret[${i}]="${newline}"
 25     i=$(( i+1 ))
 25 done

which I think must be overly complicated (especially the repetition in the for loop), but I can't make it any better at the moment and would really appreciate some pointers.


Also, as this was an exercise to help me understand a little more about what linux does upon login, any alternate routes using files I haven't thought of are very welcome.

Thanks in advance

Apple

Last edited by Apple (2013-04-02 20:42:45)

Offline

#2 2013-04-03 11:11:20

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,841

Re: Adding lines of users TODO to motd

I'm not sure what you're after with motd and /etc/issue. As far as I can make out (not gone through that thread in detail) but isn't that displayed before the user logs on?
If so, how do you know what who's to do list to display?

As for the code, try this:

 sed -n '/^.*:/,+1 p' $TODOFILE

It may not be exactly what you want, but from your description, I think it'll be close.

Last edited by skanky (2013-04-03 11:12:00)


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#3 2013-04-03 11:57:24

Apple
Member
Registered: 2013-03-30
Posts: 25

Re: Adding lines of users TODO to motd

Thanks for the reply skanky

I'm just using the ASCII art from the /etc/issue thread - I'm putting it in an unrelated file.

I tried to use

sed '...,+1p'

originally, but once I had the two lines I couldn't save them as different variables in order to put them in the ASCII picture in different places. I attempted something with

IFS=$"\n"

but couldn't get that to work.

That was the main problem - separating the two lines from one title.

Offline

#4 2013-04-03 12:35:42

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,841

Re: Adding lines of users TODO to motd

Ah okay, try this (you may need to tweak it):

eval $(awk -F: '/^.*:/ { todo = $1
                  getline
                  todolist[todo] = $0}

           END { for (todo in todolist) 
           { 
               printf("TODO%d=%s;ITEM%d=%s", i, todo, i++, todolist[todo])
           }
     }' testfile)

EDIT: apologies for the formatting.

The other two issues, you're running this when they have logged on to the console, yes?

Last edited by skanky (2013-04-03 12:36:11)


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#5 2013-04-03 13:08:46

Apple
Member
Registered: 2013-03-30
Posts: 25

Re: Adding lines of users TODO to motd

Cheers, I'll give that a go when I get back to my laptop.

With the other two, yes, kinda.

I'm trying to move the message to as early in the logging in process as possible (purely for learning purposes). At the moment I call the executeable from /etc/profile before I call any bashrc, so I have some env variables but I'm looking for a way to do it earlier. From what I've found I think all env variables at that point have come from the entry in /etc/passwd, but I can't see how to add another variable in there as the syntax is odd.

I know the /etc/motd file is printed out before the /etc/profile file is called, so I think the motd file doesn't have access to any env variables. My original aim was to put the message there and there seems to be something in PAM that calls the motd. I thought if I could make the PAM call user specific I coult create a different motd for each user and echo the message into each user's file upon the previous logout, but again different syntax that I can't understand.

Offline

#6 2013-04-03 13:14:48

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,841

Re: Adding lines of users TODO to motd

Okay, I think I understand now. The problem is, I only really know the Bash start-up, and not what goes on before that, so can't really help there, sorry.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

Board footer

Powered by FluxBB