List the scripts used during a launch of session [Quick Guide]

1:35 pm October 25, 20166733

I. introduction

in this short tutorial, we will see how to use the command strace to list all of the files that are executed when a session is opened.

Indeed, we have seen in the tutorial above, .bashrc and .bash_profile, what’s the difference? , that when creating a session or open a shell, several scripts are executed:

  • to manage the variables of environments
  • to manage aliases
  • to manage auto-complete
  • etc.

in several contexts, and particularly when you want to change any of these files, it may be interesting to know the complete list of the files executed when a login script is run

II. Using strace and grep to monitor the login shell

order strace is a tool for debugging under Linux that allows you to monitor system of a program calls. this is a very useful and effective tool that is not easy to handle when we started .

The possibility to list the files executed during a launch of session takes place in three steps, we will initially put the output of the command “strace”, generally very wordy, in a file named strace01.out :

 strace o strace01.out e open f bash - login-i 

the purpose of the previous command is capture all system calls made during the execution of the command “ bash – login – i []» , which allows her to run a shell login.” With the option “ o ‘ to strace, we write all output to the file strace01.out . Option “ e ” allows it to filter only the system calls that interest us, in this case here, file openings in the system file , so the call system ‘open’

Note : for more information about system calls, I direct you to this article: call system

so the next step is to purify our output file to retrieve only a little the interesting information. Specifically, we will exclude among calls made systems, those who answered a “ENOENT”, that is to say “ Error No. ENTry “, when the file does not exist. ” exclusion of a term is possible through the option “ v command ‘grep’ :

 grep v ENOENT strace01.out | grep-"|" cut - d "-f2 |" egrep "/ etc | $HOME" 

we will also use the command “grep” in order to retrieve only the orders containing a double quote, then we will use ‘cut’ to cut out remaining to get only the part after the double quote.

Note: To avoid duplicates that may complicate the exit to read, I advise you to add “ | sort | uniq ” at the end of the previous command;). These allow respectively to sort alphabetically the output then eliminate duplicates.

Finally, we will use ‘egrep’, , which is nothing other than the command ‘grep’ with the possibility of using regular expressions, in order to retrieve only the lines simply “ / etc ” or the contents of the environment variable ‘$HOME ‘.

Note: When opening a session, the environment variables are initialized and they can then be used by of other scripts. The $HOME variable contains the path to the home of the current user.

Ok! Now analyze the output from such a command:

[email protected]:~# grep v ENOENT OUT |] grep-"|" cut - d "-f2 |" egrep "/ etc: $HOME" | spell | uniq /etc/bash.bashrc /etc/bash_completion.d/debconf /etc/bash_completion.d/desktop-file-validate /etc/bash_completion.d/grub /etc/bash_completion.d/initramfs-tools /etc/bash_completion.d/inkscape /etc/bash_completion.d/insserv /etc/bash_completion.d/libreoffice.sh /etc/bash_completion.d/pon /etc/bash_completion.d/pulseaudio-bash-completion.sh /etc/bash_completion.d/pygmentize /etc/bash_completion.d/unar /etc/bash_completion.d/whiptail/etc/group/etc/inputrc /etc/ld.so.cache /etc/nsswitch.conf/etc/passwd/etc/profile /etc/profile.d/bash_completion.sh /etc/profile.d/vte-2.91.sh /etc/profile.d/vte.sh /root/.bash_history /root/.profile [] /root/.bashrc 

not surprisingly, we find for example /root/.bashrc which is the first file that we think of when we want to declare a variable of environment. Also, we find / etc/bash_bashrc , which is nothing other than .bashrc valid for all users.

Note: I used the commands “ | spell | uniq ‘ to sort and remove duplicates in the output. Without using these commands, we can see what file between /root/.bashrc and / etc/bashrc is executed last which overload and so “replaces” the other 😉

us see also, and this dependsdes facilities, different files from / etc/bash_completion which allows to declare shortcuts for bash completion.

More generally, if you want to know what makes a listed file, just read it via the command “cat”.

I hope that this tutorial has been helpful. Feel free to use the comments or our forum to comment or ask questions.