-1

When I open gnome-terminal, instead of presenting me with my default Bash shell, it shows:

sh-4.4$

This began happening since I added DISPLAY=:0 to my crontab -e file which now looks as follows:

DISPLAY=:0

0 0,6,12,18 * * * /usr/bin/gnome-terminal -e /home/orschiro/bin/updates.sh
0 0,6,12,18 * * * /usr/bin/gnome-terminal -e /home/orschiro/bin/rclone.sh

And also of interest:

sh-4.4$ ls -l /bin/sh
lrwxrwxrwx. 1 root root 4 18. Jun 10:30 /bin/sh -> bash

enter image description here

orschiro
  • 1,005
  • Please [edit] and add the output of grep $(whoami) /etc/passwd and cat ~/.bashrc using the formatting tools. – dessert Jul 04 '18 at 12:03
  • 1
    This is your default bash shell. Probably you have tinkered with PS1 in .bashrc or .profile. –  Jul 04 '18 at 12:11
  • The only way I can think to get the string sh-4.4 would be to have symlinked bash to /bin/sh (so that bash is invoked as sh, with the -norc switch) - you'd also need to have changed your terminal profile to use /bin/sh to observe this. Please check you terminal profile settings (in particular the "use custom command" settings) and add the output of ls -l /bin/sh to your question – steeldriver Jul 04 '18 at 12:12
  • OK so in that case it's probably not a change to your terminal profile, but the fact that the cron environment sets SHELL=/bin/sh - I still think you may have symlinked /bin/sh to bash for that to result in the prompt string sh-4.4$ though (if sh were dash the default prompt would be a simple $) – steeldriver Jul 04 '18 at 12:32
  • 2
    I think you are right. See my edits. I am on Fedora 28. Maybe that's the default symlinked behaviour? – orschiro Jul 04 '18 at 12:40
  • 4
    So, this isn't about Ubuntu at all then? – steeldriver Jul 04 '18 at 12:41
  • can you provide the result of the basic command $whoami? –  Jul 04 '18 at 12:48
  • The output of $whoami is empty. – orschiro Jul 04 '18 at 12:52
  • I will experiment with something like this in my crontab: 0 0,6,12,18 * * * /usr/bin/gnome-terminal -e "bash -c '/home/orschiro/bin/updates.sh';bash" – orschiro Jul 04 '18 at 12:54
  • I don't see why your crontab would be relevant here. Please [edit] your question and show us i) the output of ls -l /bin/bash ii) what happens if you just run bash after opening the terminal and iii) the output of echo $PS1. – terdon Jul 04 '18 at 13:56
  • @orschiro The command is whoami, not $whoami. The $ that damadam used was supposed to represent the shell`s prompt. – Kusalananda Jul 04 '18 at 14:13
  • 4
    Also, why, oh why, do you run the scripts in a terminal emulator from your crontab. That's totally unnecessary. – Kusalananda Jul 04 '18 at 14:18
  • Do these two scripts (attempt to) output content to your screen? – Chris Davies Jul 04 '18 at 15:37
  • Why was this migrated? – Sergiy Kolodyazhnyy Jul 04 '18 at 21:44

1 Answers1

1

I'm assuming this is the gnome-terminal started from your cronjob.

There is absolutely no need to run the cronjob scripts inside gnome-terminal. Doing so would mean that the jobs would fail if gnome-terminal could not be opened (which would probably happen if you weren't using the desktop at the time).

Just use

0 0,6,12,18 * * * "$HOME"/bin/updates.sh
0 0,6,12,18 * * * "$HOME"/bin/rclone.sh

Any output from the scripts will be emailed to you, assuming local email delivery was enabled. To save the output to a log file, use a redirection:

0 0,6,12,18 * * * "$HOME"/bin/updates.sh >>"$HOME"/updates.log"
0 0,6,12,18 * * * "$HOME"/bin/rclone.sh  >>"$HOME"/rclone.log"

The environment that the cronjobs are running in is different from the one you usually have when logged in through a graphical desktop environment. For one thing, your default shell may not be set in the SHELL environment variable, which is why gnome-terminal starts /bin/sh instead of bash (sh is bash on your system, but runs in POSIX compatibility mode when invoked as sh).

When logged in on the graphical desktop environment, opening gnome-terminal as usual would give you your default shell. If it doesn't, it's because there's a gnome-terminal-server process running which was started by the cron jobs. Terminate this process by either rebooting or by using pkill -f gnome-terminal-server.

See also the comment posted by JdeBP below.

Kusalananda
  • 333,661
  • 1
    Actually, no. This does not get fixed without ensuring that the GNOME Terminal server process terminates. See https://unix.stackexchange.com/a/333578/5132 and https://unix.stackexchange.com/a/407863/5132 for why it turns out that the mucking around with cron is important and why it is affecting all GNOME Terminals. – JdeBP Jul 04 '18 at 14:42
  • @JdeBP Urgh, it uses a server/client thingy. Well that sucks. Ok, I'll update. – Kusalananda Jul 04 '18 at 14:56