You are not logged in.

#1 2013-07-03 16:21:00

Konstantin_hu
Banned
Registered: 2012-05-14
Posts: 84
Website

How can I autostart my own bash script after login?

Hi!

I made a small bash script "wp" which upload files from a file list (~/uploads.txt), and comment them from the list when uploading is ready. It writes a log file in "~/uploads.log" and it invokes the program similar to "wget" but called "wput". I public it, maybe it is useful for others too:

#!/bin/bash
if [ -z $(pgrep ^wp$) ]
then 
  :
else 
  echo "wp script is already running!"
  exit
fi

host="ftp://yourusername:yourpassword@ftp.your_ftp_server.com"

while read f;
do
 ret=""
 if [ "${f:0:1}" = "#" -o "$f"1 = 1 ] 
 then
  if [ "$f"1 = 1 ] 
  then
   #read command feed a lot of empty string, this line is to deal with them, empty command :
   :
  else
   #first character is a remark sign in uploads.txt # then message -> :
   echo "remark line skipped: "$f 
  fi
 else
  #while string $ret is empty
  while [ -z "$ret" ]
  do
   wput "$f" --tries=-1 $host 2>&1|tee -a ~/uploads.log 
   ret=$(tail -n 1 ~/uploads.log|grep "FINISHED\|Nothing\|Skipped\|Transfered")
  done
  #if $ret is not empty then upload was successful -> comment the line in uploads.txt
  if [ -n "$ret" ]
  then
   cat ~/uploads.txt > ~/uploads_bak.txt
   awk -v f="$f" '{if ($0==f && $0!~/#/) print "#" $0; else print $0;}' ~/uploads_bak.txt > ~/uploads.txt
  fi
 fi 
done < ~/uploads.txt

I would like to start this script called "wp" when I login, with this command sequence (avoiding multiple starting):

if [ -z $(pgrep ^wp$) ]
then 
  echo "starting wp script..."
  wp
else 
  echo "wp script is already running!"
fi

My question is which file should I place this invoking command sequence in to start my script at every login in a terminator / xterm window? Recently I placed it in "~/.bashrc" but I realized it starts when I manually launch terminator / xterm.

Last edited by Konstantin_hu (2013-07-03 16:23:38)

Offline

#2 2013-07-03 16:46:34

cris9288
Member
Registered: 2013-01-07
Posts: 347

Re: How can I autostart my own bash script after login?

It depends. have a look at this

https://wiki.archlinux.org/index.php/Autostarting

Offline

#3 2013-07-03 16:49:32

Konstantin_hu
Banned
Registered: 2012-05-14
Posts: 84
Website

Re: How can I autostart my own bash script after login?

Thx, I have read that article before asking my question, but I still don't know which file to use.

Offline

#4 2013-07-03 17:45:35

FlyingHappy
Member
From: Cincinnati, OH
Registered: 2011-04-18
Posts: 186

Re: How can I autostart my own bash script after login?

What DE/WM are you using?

Offline

#5 2013-07-03 19:39:59

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,804
Website

Re: How can I autostart my own bash script after login?

Konstantin_hu wrote:

My question is which file should I place this invoking command sequence in to start my script at every login in a terminator / xterm window? Recently I placed it in "~/.bashrc" but I realized it starts when I manually launch terminator / xterm.

HUH?

You want it to run with *every* terminal you open ... but not with the ones you open manually?  Can you clarify that?


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#6 2013-07-03 19:44:50

Konstantin_hu
Banned
Registered: 2012-05-14
Posts: 84
Website

Re: How can I autostart my own bash script after login?

No, I just want it to start once, when I login, in a terminator / xterm window.

Offline

#7 2013-07-03 19:52:49

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,804
Website

Re: How can I autostart my own bash script after login?

Why when you open a terminal window, why not when you login to your x session?


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#8 2013-07-03 20:17:05

FlyingHappy
Member
From: Cincinnati, OH
Registered: 2011-04-18
Posts: 186

Re: How can I autostart my own bash script after login?

That is what he is saying Trilby, when he logs into the computer, he wants it to start a terminal with his script running.  What WM/DE are you using Kinstantin?

Offline

#9 2013-07-03 20:25:58

defer
Member
From: Finland
Registered: 2013-06-25
Posts: 46
Website

Re: How can I autostart my own bash script after login?

If i got it right, you should try exec xterm -c wp to ~/.xinitrc

Last edited by defer (2013-07-03 20:26:24)

Offline

#10 2013-07-03 20:43:52

2ManyDogs
Member
Registered: 2012-01-15
Posts: 1,670

Re: How can I autostart my own bash script after login?

defer wrote:

If i got it right, you should try exec xterm -c wp to ~/.xinitrc

"exec" replaces the running process, so if he uses this line before he starts his window manager, the wm won't start.

Before we go telling him how to modify his xinitrc, we need to know if he's even using one. As FlyingHappy has asked (twice now) "What DE/WM are you using?"

Offline

#11 2013-07-03 21:01:57

Konstantin_hu
Banned
Registered: 2012-05-14
Posts: 84
Website

Re: How can I autostart my own bash script after login?

I am using LXDE.

Offline

#12 2013-07-03 21:16:18

2ManyDogs
Member
Registered: 2012-01-15
Posts: 1,670

Re: How can I autostart my own bash script after login?

LXDE has a built-in autostart mechanism. Use it to start xterm and run your script when you log in.

https://wiki.archlinux.org/index.php/LX … t_Programs

Last edited by 2ManyDogs (2013-07-03 21:18:57)

Offline

#13 2013-07-04 03:37:29

Konstantin_hu
Banned
Registered: 2012-05-14
Posts: 84
Website

Re: How can I autostart my own bash script after login?

Thx, meanwhile I realized that I can start it as: "terminator -e wp"

Offline

#14 2013-07-04 07:35:39

ConnorBehan
Trusted User (TU)
From: Long Island NY
Registered: 2007-07-05
Posts: 1,356
Website

Re: How can I autostart my own bash script after login?

So this is [solved]?


6EA3 F3F3 B908 2632 A9CB E931 D53A 0445 B47A 0DAB
Great things come in tar.xz packages.

Offline

Board footer

Powered by FluxBB