It's possibly to create something like a batch for upgrade by ssh?

Usually for check the upgrade i use my pc by ssh and use this command:
sudo apt-get -y update && sudo apt-get -y -f dist-upgrade

My question it’s… it’s possibly to create a somethigs like a “link” or somethigs like a “alias” for this command ?

For example whit a “aliases” when logged to ssh i can only put a command like update and after it’s automatic launch the correctly command posted above ?

EDIT
Possibly similar question here:

Try to read…

EDIT 2
And i found it’s can possibly add aliases on .bashrc… yeah but where’s this files ??

Yes, there is no reason why you couldn’t do that.

I’d probably make a shell script with the desired commands in it, make it executable and put it somewhere like /usr/local/bin but there are other ways to do it like creating an alias.

I myself wouldn’t have the -y -f on the dist-upgrade command as i’d want to review the output first.

.bashrc is in your home directory (/home/osmc) as it have a . at the start of the filename it means it’s invisible so when running the ls command you need the -a argument. If just editing you can do this without needing to do anything.

i have choose to create a .bash_aliases on root folder how it’s suggested on .bashrc files in home folder.

But i thinks i need to reboot my pi2 for obtain this aliases works…

Meanwhile on .bashrc it’s suggested this:


# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

I have created a new files… in /root and i thinks this files it’s loaded at boot… i need only to test it.

For -y in dist-upgrade… i have put this because i thinks it’s usefull. If it’s present some upgrade bacause not upgrade it’s directly ? OSMC it’s not a fully OS and the sources and all your upgrade it’s tested before to released… whitout -y i need only to answered yes :slight_smile:

Put -y because I trust what is released from OSMC team :slight_smile:

It’s not saying to put it in /root, it’s saying to put it in the home directory which is /home/osmc or sometimes referred to simply as ~

You don’t need to reboot to test these changes (I would as I’m lazy), you can simply re-read the .bash_aliases file to apply those changes now if you want.

and how i can re-read the bash files ?

source ~/.bashrc

Oh yes… i have already do now :slight_smile:

I have not modified the .bashrc files but i have add an external file when it’s suggested on same files… i have test and it’s work apparently…

@jb2cool

I have need a explanation…how i need exactly to put the files ?? On /root of on /home/osmc ?

I have tryed to create a external files called .bash_aliases like it’s suggested on .bashrc bat apparently the alias it’s not works also after a reboot.

Very strange…

Seems to work fine here.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Feb 15 16:01:47 2017 from desktop.local
osmc@osmctestpi:~$ cat .bash_aliases
alias ll='ls -la'
osmc@osmctestpi:~$ ll
total 384
drwxr-xr-x 8 osmc osmc   4096 Feb 15 16:03 .
drwxr-xr-x 3 root root   4096 Dec 31  1969 ..
-rw-r--r-- 1 osmc osmc     18 Feb 15 16:03 .bash_aliases
-rw------- 1 osmc osmc   3877 Feb 15 16:03 .bash_history
-rw-r--r-- 1 osmc osmc    220 Oct 18  2014 .bash_logout
-rw-r--r-- 1 osmc osmc   3515 Oct 18  2014 .bashrc
drwx------ 3 osmc osmc   4096 Oct 13 17:22 .config
drwxr-xr-x 7 osmc osmc   4096 Aug  3  2016 .kodi
-rw-r--r-- 1 osmc osmc    675 Oct 18  2014 .profile
drwxr-xr-x 2 osmc osmc   4096 Jun 21  2016 Movies
drwxr-xr-x 2 osmc osmc   4096 Jun 21  2016 Music
drwxr-xr-x 2 osmc osmc   4096 Jun 21  2016 Pictures
drwxr-xr-x 2 osmc osmc   4096 Jun 21  2016 TV Shows
-rwxr-xr-x 1 osmc osmc 337659 Feb 14 13:39 texturecache.py
osmc@osmctestpi:~$

Works fine for me too.

SSH into your device and create the file (it doesn’t exist by default) with;
nano .bash_aliases

In the text editor window that comes up enter your desired aliases one per line. All my example one has in it is;
alias update='sudo apt-get update && sudo apt-get dist-upgrade -y'

For clarity, the file is /home/osmc/.bash_aliases
Not in /root like you suggested earlier.

1 Like

Also, make sure you don’t use sudo to create .bash_aliases which will result in the file being owned by root and unreadable by osmc.

1 Like

To answer at @ActionA and @jb2cool… i thinks i have understood how it’s works… try to explain:
I thinks the .bashrc files it’s be read/loaded every time i start a bash session or also a SSH session from my pc.
Example:

  1. if i open a SSH using “root” as user it’s be loaded the file on:
    /root/.bashrc

  2. instead… if i open a SSH by me pc using “osmc” as user the file loaded it’s:
    /home/omsc/.bashrc

Meanwhile how i have usually use the “root” user for my ssh config i have created this two files.
on /root/.bashrc i have put this:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

Instead i use “root” as user the symbol “~” report to /root… infact this portion of goes to be load /root/.bash_aliases files if exist and on this files i have put this:

alias update='clear && echo "Questo è il file su /root" && sleep 5 && echo "" && sudo apt-get update && sudo apt-get -y -f dist-upgrade'
alias restart='sudo systemctl restart mediacenter'

This is my .bash_alises files pushed on /root path… and now… IT’S WORK whitout any problems :slight_smile:

I had to figure out just the question of “user” i stay to use for my SSH session… and THAT’S IT’S ALL :slight_smile:

It’s all correct ?? If i commit some error say to me…

Meanwhile now i’m another problems…because the alias now it’s work but when i use the update command now i obtain this trouble… look:

Trovato http://ftp.debian.org jessie/contrib Translation-en
Trovato http://ftp.debian.org jessie/main Translation-it
Trovato http://ftp.debian.org jessie/main Translation-en
Trovato http://ftp.debian.org jessie/non-free Translation-en
Ign http://apt.osmc.tv jessie/main Translation-it_IT
Ign http://apt.osmc.tv jessie/main Translation-it
Ign http://apt.osmc.tv jessie/main Translation-en
Recuperati 13,1 kB in 20s (653 B/s)
Lettura elenco dei pacchetti... Fatto
E: Opzione a riga di comando "y" [da -y] sconosciuta.
root@osmc:~#

I don’t understand because i obtain the last error before prompt… it’s in italian but i thinks you can understand because they append.

I thinks because i commit some error on alias update command… i don’t understand where and when the alias it’s bad wrote… if you have some suggestion…

I test immediatelly… it’s very strange because if i use copy and paste manually on ssh session i don’t have problems.

I have problems only when this used on alias… it’s possibly because i can’t use the symbol “-” on alias ??

EDIT

Lol… i thinks there’s some problems whit symbols i can use… look:

I think I tried it with -y and it worked ok. Try taking out the -f so that you only have one argument.

I’d also slim down the command to just have the basic functionality before you start getting too clever.

Start with this;
alias update='sudo apt-get update && sudo apt-get dist-upgrade -y'

and then if that works then and only then move forward.

mmmmmmmm… i have tryed but apparently i have obtain same errors…

I thinks i have found a solution… tryed to set commands as variable inside .bashrc…

EDIT
I have tryed this:

alias update='sudo apt-get update && sudo apt-get -y -f dist-upgrade'

Apparently it’s working… i don’t understand because goes in error when i add the other commands… i need to test again.

EDIT2
This:

alias update='clear && echo "Questo è il file su /root" && sleep 5 && sudo apt-get update && sudo apt-get -y -f dist-upgrade'

This goes in error:

Lettura elenco dei pacchetti... Fatto
E: Opzione a riga di comando "y" [da -y] sconosciuta.

EDIT3

It’s very strange situation… it’s sometime work and other time goes in error.

I don’t really understand how it’s works…

FINAL EDIT for Today:

Apparently there’s working whitout any problems:

alias update='clear && echo "Avvio il file sul ROOT..." && echo && sudo apt-get update && sudo apt-get -y -f dist-upgrade'

If next time goes in error i go to crazy…

@jb2cool @ActionA i’m need to back to this trouble because i have found a possibly bug… try to explain what’s appened… this is my current bash_aliases file:

# Alias definitions.
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF
#alias <command>='command'
#file on /root
alias restart='sudo systemctl restart mediacenter'
alias update='clear && echo "Avvio il file sul ROOT..." && echo && sudo apt-get update && sudo apt-get -y -f dist-upgrade'
alias test1='sudo systemctl restart mediacenter'

When i launch SSH Session… the “restart” commands not work and obtain an error says:

Failed to restart mediacenter\x0d.service: Unit mediacenter\x0d.service failed to load: No such file or directory.

Also the “update” it’s not work!!! I obtain the error already say here!

Apparently only the “test1” WORK!!!
Only the LAST alias work… because ??? I don’t have absolutely idea…

I have also tryed to change order of alias…if i put the Alias update at Last line of files… this works and the other 2 no work… very strange!

osmc@192.168.0.37's password:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Feb 24 16:11:08 2017 from desktop.local
osmc@osmctestpi:~$ cat .bash_aliases
alias ll='ls -la'
alias restart1='sudo systemctl restart mediacenter'
alias restart2='sudo systemctl restart mediacenter'
alias restart3='sudo systemctl restart mediacenter'
alias restart4='sudo systemctl restart mediacenter'
osmc@osmctestpi:~$ restart1
osmc@osmctestpi:~$ restart2
osmc@osmctestpi:~$ restart3
osmc@osmctestpi:~$ restart4
osmc@osmctestpi:~$

No problems here. They all behave as expected without issue.

you can try to use ssh session as “root” ?
Now i have tryed to put my alias directly on .bashrc files on /root…

Apparently it’s working… but if i use the “tricks” whit .bash_aliases i obtain error… i don’t understand because.

EDIT
@ActionA

I don’t have idea…this is my situation… look what’s appened on my osmc:

Using username "root".
root@192.168.1.4's password:
Send automatic password
Access denied
root@192.168.1.4's password:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Feb 24 22:45:50 2017 from 192.168.1.2
-bash: $'\r': comando non trovato
root@osmc:~# cat ~/.bash_aliases
# Alias definitions.
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF
#alias <command>='command'
#file on /root

alias restart='sudo systemctl restart mediacenter'
alias update='clear && echo "Avvio il file sul ROOT..." && echo && sudo apt-get update && sudo apt-get -y -f dist-upgrade'
alias test1='ls -la'
root@osmc:~# test1
"s: opzione non valida -- "
Try 'ls --help' for more information.
root@osmc:~#

If i put the SAME alias directly on .bashrc apparently it’s working whitout any problems.

EDIT
I don’t have absolutely idea because that’s appened… but apparently if i put some alias on .bash_aliases only the last alias work correctly.

I have put the same alies directly on /root/.bashrc files and all aliases works…

It’s possibly the problems it’s kitty ?? It’s possibly the problems it’s my version of bash on my osmc setup ??
Or it’s possibly the problems it’s only because i use the “root” user ??

.bash_aliases did not work as root user, quite possibly that is by design. But after adding to .bashrc i get same behavior, they all work.