how to run two commands in sudo?

For your command you also could refer to the following example:

sudo sh -c 'whoami; whoami'


sudo can run multiple commands via a shell, for example:

$ sudo -s -- 'whoami; whoami'
root
root

Your command would be something like:

sudo -u db2inst1 -s -- "db2 connect to ttt; db2 UPDATE CONTACT SET EMAIL_ADDRESS = '[email protected]'"

If your sudo version doesn't work with semicolons with -s (apparently, it doesn't if compiled with certain options), you can use

sudo -- sh -c 'whoami; whoami'

instead, which basically does the same thing but makes you name the shell explicitly.


If you would like to handle quotes:

sudo -s -- <<EOF
id
pwd
echo "Done."
EOF