11

I want to create an alias for pagsh that will immediately get me the admin kerberos ticket.

The problem is that I can't figure out how to specify a command for the bash to run, but still continue with the interactive session after the command is done.

My current shot is:

alias admin=pagsh -c "bash -c \"kinit xtoth1@ADMIN.META\""

but bash logically ends right after kinit is done. How can I push a custom command into a begging of an interactive session of bash? I still need to run .bashrc normally, therefore I can't use --rcfile

Šimon Tóth
  • 35,456
  • 20
  • 106
  • 151

3 Answers3

10

My advice would be using a custom bashrc file with --rcfile that sources your .bashrc, ex :

alias admin=pagsh -c "bash --rcfile myrc"

myrc :

source ~/.bashrc
kinit xtoth1@ADMIN.META
OneOfOne
  • 95,033
  • 20
  • 184
  • 185
2

If what you need is only a line or two, you can use the cool bash feature of "Process Substitution"[1] to provide it right on the invocation line. e.g. (to run a bash in a specific python virtualenv):

bash --rcfile <(echo '. ./pyvenv/bin/activate')

multiple lines are not a problem, nor is using vars or helpers:

bash --rcfile <(echo echo "Starting at `date`"; echo cd $HOME)

[1] man bash and look for "Process Substitution". Note that this is not supported on all systems, but it should work on all Linux.

Rob Starling
  • 3,868
  • 3
  • 23
  • 40
1

What about following?

alias admin='pagsh -c "bash -c \"kinit xtoth1@ADMIN.META; exec bash\""'

or even

alias admin='pagsh -c "kinit xtoth1@ADMIN.META; exec bash"'

might work. (I do not have working openafs environment around to test it properly.)

xkollar2
  • 11
  • 2