Hadoop Syntax error: word unexpected (expecting ")") - hadoop

sh start-all.sh
This script is Deprecated. Instead use start-dfs.sh and start-yarn.sh
start-all.sh: 99: /home/songtian/下载/hadoop-2.6.0/sbin/../libexec/hadoop-config.sh: Syntax error: word unexpected (expecting ")")
And I open the hadoop-config.sh,but there is no error in 99.The next content is hadoop-config and there is no error in line 99.I don't know whether I understand the error of the sh start-all.sh. What should I modify.
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# included in all the hadoop scripts with source command
# should not be executable directly
# also should not be passed any arguments, since we need original $*
# Resolve links ($0 may be a softlink) and convert a relative path
# to an absolute path. NB: The -P option requires bash built-ins
# or POSIX:2001 compliant cd and pwd.
# HADOOP_CLASSPATH Extra Java CLASSPATH entries.
#
# HADOOP_USER_CLASSPATH_FIRST When defined, the HADOOP_CLASSPATH is
# added in the beginning of the global
# classpath. Can be defined, for example,
# by doing
# export HADOOP_USER_CLASSPATH_FIRST=true
#
# HADOOP_USE_CLIENT_CLASSLOADER When defined, HADOOP_CLASSPATH and the jar
# as the hadoop jar argument are handled by
# by a separate isolated client classloader.
# If it is set, HADOOP_USER_CLASSPATH_FIRST
# is ignored. Can be defined by doing
# export HADOOP_USE_CLIENT_CLASSLOADER=true
#
# HADOOP_CLIENT_CLASSLOADER_SYSTEM_CLASSES
# When defined, it overrides the default
# definition of system classes for the client
# classloader when
# HADOOP_USE_CLIENT_CLASSLOADER is enabled.
# Names ending in '.' (period) are treated as
# package names, and names starting with a
# '-' are treated as negative matches.
# For example,
# export HADOOP_CLIENT_CLASSLOADER_SYSTEM_CLASSES="-org.apache.hadoop.UserClass,java.,javax.,org.apache.hadoop."
this="${BASH_SOURCE-$0}"
common_bin=$(cd -P -- "$(dirname -- "$this")" && pwd -P)
script="$(basename -- "$this")"
this="$common_bin/$script"
[ -f "$common_bin/hadoop-layout.sh" ] && . "$common_bin/hadoop-layout.sh"
HADOOP_COMMON_DIR=${HADOOP_COMMON_DIR:-"share/hadoop/common"}
HADOOP_COMMON_LIB_JARS_DIR=${HADOOP_COMMON_LIB_JARS_DIR:-"share/hadoop/common/lib"}
HADOOP_COMMON_LIB_NATIVE_DIR=${HADOOP_COMMON_LIB_NATIVE_DIR:-"lib/native"}
HDFS_DIR=${HDFS_DIR:-"share/hadoop/hdfs"}
HDFS_LIB_JARS_DIR=${HDFS_LIB_JARS_DIR:-"share/hadoop/hdfs/lib"}
YARN_DIR=${YARN_DIR:-"share/hadoop/yarn"}
YARN_LIB_JARS_DIR=${YARN_LIB_JARS_DIR:-"share/hadoop/yarn/lib"}
MAPRED_DIR=${MAPRED_DIR:-"share/hadoop/mapreduce"}
MAPRED_LIB_JARS_DIR=${MAPRED_LIB_JARS_DIR:-"share/hadoop/mapreduce/lib"}
# the root of the Hadoop installation
# See HADOOP-6255 for directory structure layout
HADOOP_DEFAULT_PREFIX=$(cd -P -- "$common_bin"/.. && pwd -P)
HADOOP_PREFIX=${HADOOP_PREFIX:-$HADOOP_DEFAULT_PREFIX}
export HADOOP_PREFIX
#check to see if the conf dir is given as an optional argument
if [ $# -gt 1 ]
then
if [ "--config" = "$1" ]
then
shift
confdir=$1
if [ ! -d "$confdir" ]; then
echo "Error: Cannot find configuration directory: $confdir"
exit 1
fi
shift
HADOOP_CONF_DIR=$confdir
fi
fi
# Allow alternate conf dir location.
if [ -e "${HADOOP_PREFIX}/conf/hadoop-env.sh" ]; then
DEFAULT_CONF_DIR="conf"
else
DEFAULT_CONF_DIR="etc/hadoop"
fi
export HADOOP_CONF_DIR="${HADOOP_CONF_DIR:-$HADOOP_PREFIX/$DEFAULT_CONF_DIR}"
# User can specify hostnames or a file where the hostnames are (not both)
if [[("$HADOOP_SLAVES"!='')&&("$HADOOP_SLAVE_NAMES"!='')]]; then
echo \
"Error: Please specify one variable HADOOP_SLAVES or " \
"HADOOP_SLAVE_NAME and not both."
exit 1
fi
# Process command line options that specify hosts or file with host
# list
if [ $# -gt 1 ]
then
if [ "--hosts" = "$1" ]
then
shift
export HADOOP_SLAVES="${HADOOP_CONF_DIR}/$1"
shift
elif [ "--hostnames" = "$1" ]
then
shift
export HADOOP_SLAVE_NAMES=$1
shift
fi
fi
# User can specify hostnames or a file where the hostnames are (not both)
# (same check as above but now we know it's command line options that cause
# the problem)
if [[("$HADOOP_SLAVES"!='')&&("$HADOOP_SLAVE_NAMES"!='')]]; then
echo \
"Error: Please specify one of --hosts or --hostnames options and not both."
exit 1
fi
if [ -f "${HADOOP_CONF_DIR}/hadoop-env.sh" ]; then
. "${HADOOP_CONF_DIR}/hadoop-env.sh"
fi
# check if net.ipv6.bindv6only is set to 1
bindv6only=$(/sbin/sysctl -n net.ipv6.bindv6only 2> /dev/null)
if [ -n "$bindv6only" ] && [ "$bindv6only" -eq "1" ] && [ "$HADOOP_ALLOW_IPV6" != "yes" ]
then
echo "Error: \"net.ipv6.bindv6only\" is set to 1 - Java networking could be broken"
echo "For more info: http://wiki.apache.org/hadoop/HadoopIPv6"
exit 1
fi
# Newer versions of glibc use an arena memory allocator that causes virtual
# memory usage to explode. This interacts badly with the many threads that
# we use in Hadoop. Tune the variable down to prevent vmem explosion.
export MALLOC_ARENA_MAX=${MALLOC_ARENA_MAX:-4}
# Attempt to set JAVA_HOME if it is not set
if [[ -z $JAVA_HOME ]]; then
# On OSX use java_home (or /Library for older versions)
if [ "Darwin" == "$(uname -s)" ]; then
if [ -x /usr/libexec/java_home ]; then
export JAVA_HOME=($(/usr/libexec/java_home))
else
export JAVA_HOME=(/Library/Java/Home)
fi
fi
# Bail if we did not detect it
if [[ -z $JAVA_HOME ]]; then
echo "Error: JAVA_HOME is not set and could not be found." 1>&2
exit 1
fi
fi
JAVA=$JAVA_HOME/bin/java
# some Java parameters
JAVA_HEAP_MAX=-Xmx1000m
# check envvars which might override default args
if [ "$HADOOP_HEAPSIZE" != "" ]; then
#echo "run with heapsize $HADOOP_HEAPSIZE"
JAVA_HEAP_MAX="-Xmx""$HADOOP_HEAPSIZE""m"
#echo $JAVA_HEAP_MAX
fi
# CLASSPATH initially contains $HADOOP_CONF_DIR
CLASSPATH="${HADOOP_CONF_DIR}"
# so that filenames w/ spaces are handled correctly in loops below
IFS=
if [ "$HADOOP_COMMON_HOME" = "" ]; then
if [ -d "${HADOOP_PREFIX}/$HADOOP_COMMON_DIR" ]; then
export HADOOP_COMMON_HOME=$HADOOP_PREFIX
fi
fi
# for releases, add core hadoop jar & webapps to CLASSPATH
if [ -d "$HADOOP_COMMON_HOME/$HADOOP_COMMON_DIR/webapps" ]; then
CLASSPATH=${CLASSPATH}:$HADOOP_COMMON_HOME/$HADOOP_COMMON_DIR
fi
if [ -d "$HADOOP_COMMON_HOME/$HADOOP_COMMON_LIB_JARS_DIR" ]; then
CLASSPATH=${CLASSPATH}:$HADOOP_COMMON_HOME/$HADOOP_COMMON_LIB_JARS_DIR'/*'
fi
CLASSPATH=${CLASSPATH}:$HADOOP_COMMON_HOME/$HADOOP_COMMON_DIR'/*'
# default log directory & file
if [ "$HADOOP_LOG_DIR" = "" ]; then
HADOOP_LOG_DIR="$HADOOP_PREFIX/logs"
fi
if [ "$HADOOP_LOGFILE" = "" ]; then
HADOOP_LOGFILE='hadoop.log'
fi
# default policy file for service-level authorization
if [ "$HADOOP_POLICYFILE" = "" ]; then
HADOOP_POLICYFILE="hadoop-policy.xml"
fi
# restore ordinary behaviour
unset IFS
# setup 'java.library.path' for native-hadoop code if necessary
if [ -d "${HADOOP_PREFIX}/build/native" -o -d "${HADOOP_PREFIX}/$HADOOP_COMMON_LIB_NATIVE_DIR" ]; then
if [ -d "${HADOOP_PREFIX}/$HADOOP_COMMON_LIB_NATIVE_DIR" ]; then
if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
JAVA_LIBRARY_PATH=${JAVA_LIBRARY_PATH}:${HADOOP_PREFIX}/$HADOOP_COMMON_LIB_NATIVE_DIR
else
JAVA_LIBRARY_PATH=${HADOOP_PREFIX}/$HADOOP_COMMON_LIB_NATIVE_DIR
fi
fi
fi
# setup a default TOOL_PATH
TOOL_PATH="${TOOL_PATH:-$HADOOP_PREFIX/share/hadoop/tools/lib/*}"
HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.dir=$HADOOP_LOG_DIR"
HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.file=$HADOOP_LOGFILE"
HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.home.dir=$HADOOP_PREFIX"
HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.id.str=$HADOOP_IDENT_STRING"
HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.root.logger=${HADOOP_ROOT_LOGGER:-INFO,console}"
if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
HADOOP_OPTS="$HADOOP_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JAVA_LIBRARY_PATH
fi
HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.policy.file=$HADOOP_POLICYFILE"
# Disable ipv6 as it can cause issues
HADOOP_OPTS="$HADOOP_OPTS -Djava.net.preferIPv4Stack=true"
# put hdfs in classpath if present
if [ "$HADOOP_HDFS_HOME" = "" ]; then
if [ -d "${HADOOP_PREFIX}/$HDFS_DIR" ]; then
export HADOOP_HDFS_HOME=$HADOOP_PREFIX
fi
fi
if [ -d "$HADOOP_HDFS_HOME/$HDFS_DIR/webapps" ]; then
CLASSPATH=${CLASSPATH}:$HADOOP_HDFS_HOME/$HDFS_DIR
fi
if [ -d "$HADOOP_HDFS_HOME/$HDFS_LIB_JARS_DIR" ]; then
CLASSPATH=${CLASSPATH}:$HADOOP_HDFS_HOME/$HDFS_LIB_JARS_DIR'/*'
fi
CLASSPATH=${CLASSPATH}:$HADOOP_HDFS_HOME/$HDFS_DIR'/*'
# put yarn in classpath if present
if [ "$HADOOP_YARN_HOME" = "" ]; then
if [ -d "${HADOOP_PREFIX}/$YARN_DIR" ]; then
export HADOOP_YARN_HOME=$HADOOP_PREFIX
fi
fi
if [ -d "$HADOOP_YARN_HOME/$YARN_DIR/webapps" ]; then
CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/$YARN_DIR
fi
if [ -d "$HADOOP_YARN_HOME/$YARN_LIB_JARS_DIR" ]; then
CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/$YARN_LIB_JARS_DIR'/*'
fi
CLASSPATH=${CLASSPATH}:$HADOOP_YARN_HOME/$YARN_DIR'/*'
# put mapred in classpath if present AND different from YARN
if [ "$HADOOP_MAPRED_HOME" = "" ]; then
if [ -d "${HADOOP_PREFIX}/$MAPRED_DIR" ]; then
export HADOOP_MAPRED_HOME=$HADOOP_PREFIX
fi
fi
if [ "$HADOOP_MAPRED_HOME/$MAPRED_DIR" != "$HADOOP_YARN_HOME/$YARN_DIR" ] ; then
if [ -d "$HADOOP_MAPRED_HOME/$MAPRED_DIR/webapps" ]; then
CLASSPATH=${CLASSPATH}:$HADOOP_MAPRED_HOME/$MAPRED_DIR
fi
if [ -d "$HADOOP_MAPRED_HOME/$MAPRED_LIB_JARS_DIR" ]; then
CLASSPATH=${CLASSPATH}:$HADOOP_MAPRED_HOME/$MAPRED_LIB_JARS_DIR'/*'
fi
CLASSPATH=${CLASSPATH}:$HADOOP_MAPRED_HOME/$MAPRED_DIR'/*'
fi
# Add the user-specified CLASSPATH via HADOOP_CLASSPATH
# Add it first or last depending on if user has
# set env-var HADOOP_USER_CLASSPATH_FIRST
# if the user set HADOOP_USE_CLIENT_CLASSLOADER, HADOOP_CLASSPATH is not added
# to the classpath
if [[("$HADOOP_CLASSPATH"!="")&&("$HADOOP_USE_CLIENT_CLASSLOADER"="")]]; then
# Prefix it if its to be preceded
if [ "$HADOOP_USER_CLASSPATH_FIRST" != "" ]; then
CLASSPATH=${HADOOP_CLASSPATH}:${CLASSPATH}
else
CLASSPATH=${CLASSPATH}:${HADOOP_CLASSPATH}
fi
fi

The error is not with the config files but the way you run those scripts.
Correct way to run the scripts is to stay in hadoop-home and apply
To start cluster
sbin/start-all.sh
To stop cluster
sbin/stop-all.sh
Or
You can go in sbin directory and do
To start cluster
./start-all.sh
To stop cluster
./stop-all.sh

I solve it.I think I should install English Ubuntu 16.04 and then I reinstall Java and Hadoop.Then the hadoop works,so amazing!

Related

Terminal window spews out some code on every startup after a hack-installation of Vagrant on M1 silicon

I don't remember when exactly the behaviour started, but I suspect it was after following the instructions for installing the Vagrant/VMWareFusion Virtual Machines for the purpose of running Vagrant on an M1 machine. Particularly, I think the Rosetta installation step broke something with the Conda environment, or it could have been the VMWare_Fusion, I am not really sure even to where to look for the leads...
On every startup of a new terminal window it spews out this (which is not a problem, but is annoying and I want to know the reason behind it).
Last login: Fri Feb 3 10:20:58 on ttys013
CONDA_DEFAULT_ENV=base
CONDA_EXE=/Users/administrateur/miniconda3/bin/conda
CONDA_PREFIX=/Users/administrateur/miniconda3
CONDA_PROMPT_MODIFIER='(base) '
CONDA_PYTHON_EXE=/Users/administrateur/miniconda3/bin/python
CONDA_SHLVL=1
CONDA_SUBDIR=osx-64
HOME=/Users/administrateur
HOMEBREW_CELLAR=/opt/homebrew/Cellar
HOMEBREW_PREFIX=/opt/homebrew
HOMEBREW_REPOSITORY=/opt/homebrew
INFOPATH=/opt/homebrew/share/info:
LC_CTYPE=UTF-8
LOGNAME=administrateur
LaunchInstanceID=<...>
MANPATH=/opt/homebrew/share/man::
MallocSpaceEfficient=1
OLDPWD=/Users/administrateur
PATH='/Users/administrateur/miniconda3/bin:/Users/administrateur/miniconda3/condabin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion Tech Preview.app/Contents/Public:/Library/Apple/usr/bin'
PWD=/Users/administrateur
SHELL=/bin/zsh
SHLVL=1
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.m4msYyw1Un/Listeners
TERM=xterm-256color
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=447
TERM_SESSION_ID=<...>
TMPDIR=/var/folders/lb/nwlpglqd33d3539m3f8wntyr0000gn/T/
USER=administrateur
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
_CE_CONDA=''
_CE_M=''
__CFBundleIdentifier=com.apple.Terminal
(base) administrateur#machine ~ %
UPD:
The contents of ~./zshrc
alias ll="ls -l"
alias lt='ls -lt | head'
alias lS='ls -lS'
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/administrateur/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/administrateur/miniconda3/etc/profile.d/conda.sh" ]; then
. "/Users/administrateur/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/Users/administrateur/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
The conda.csh file looks like this
setenv CONDA_EXE "/Users/administrateur/miniconda3/bin/conda"
setenv _CONDA_ROOT "/Users/administrateur/miniconda3"
setenv _CONDA_EXE "/Users/administrateur/miniconda3/bin/conda"
setenv CONDA_PYTHON_EXE "/Users/administrateur/miniconda3/bin/python"
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
if (! $?_CONDA_EXE) then
set _CONDA_EXE="${PWD}/conda/shell/bin/conda"
else
if ("$_CONDA_EXE" == "") then
set _CONDA_EXE="${PWD}/conda/shell/bin/conda"
endif
endif
if ("`alias conda`" == "") then
if ($?_CONDA_EXE) then
# _CONDA_PFX is named so as not to cause confusion with CONDA_PREFIX
# If nested backticks were possible we wouldn't use any variables here.
set _CONDA_PFX=`dirname "${_CONDA_EXE}"`
set _CONDA_PFX=`dirname "${_CONDA_PFX}"`
alias conda source "${_CONDA_PFX}/etc/profile.d/conda.csh"
# And for good measure, get rid of it afterwards.
unset _CONDA_PFX
else
alias conda source "${PWD}/conda/shell/etc/profile.d/conda.csh"
endif
setenv CONDA_SHLVL 0
if (! $?prompt) then
set prompt=""
endif
else
switch ( "${1}" )
case "activate":
set ask_conda="`(setenv prompt '${prompt}' ; '${_CONDA_EXE}' shell.csh activate '${2}' ${argv[3-]})`"
set conda_tmp_status=$status
if( $conda_tmp_status != 0 ) exit ${conda_tmp_status}
eval "${ask_conda}"
rehash
breaksw
case "deactivate":
set ask_conda="`(setenv prompt '${prompt}' ; '${_CONDA_EXE}' shell.csh deactivate '${2}' ${argv[3-]})`"
set conda_tmp_status=$status
if( $conda_tmp_status != 0 ) exit ${conda_tmp_status}
eval "${ask_conda}"
rehash
breaksw
case "install" | "update" | "upgrade" | "remove" | "uninstall":
$_CONDA_EXE $argv[1-]
set ask_conda="`(setenv prompt '${prompt}' ; '${_CONDA_EXE}' shell.csh reactivate)`"
set conda_tmp_status=$status
if( $conda_tmp_status != 0 ) exit ${conda_tmp_status}
eval "${ask_conda}"
rehash
breaksw
default:
$_CONDA_EXE $argv[1-]
breaksw
endsw
endif
The contents of conda.sh:
export CONDA_EXE='/Users/administrateur/miniconda3/bin/conda'
export _CE_M=''
export _CE_CONDA=''
export CONDA_PYTHON_EXE='/Users/administrateur/miniconda3/bin/python'
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
__conda_exe() (
"$CONDA_EXE" $_CE_M $_CE_CONDA "$#"
)
__conda_hashr() {
if [ -n "${ZSH_VERSION:+x}" ]; then
\rehash
elif [ -n "${POSH_VERSION:+x}" ]; then
: # pass
else
\hash -r
fi
}
__conda_activate() {
if [ -n "${CONDA_PS1_BACKUP:+x}" ]; then
# Handle transition from shell activated with conda <= 4.3 to a subsequent activation
# after conda updated to >= 4.4. See issue #6173.
PS1="$CONDA_PS1_BACKUP"
\unset CONDA_PS1_BACKUP
fi
\local ask_conda
ask_conda="$(PS1="${PS1:-}" __conda_exe shell.posix "$#")" || \return
\eval "$ask_conda"
__conda_hashr
}
__conda_reactivate() {
\local ask_conda
ask_conda="$(PS1="${PS1:-}" __conda_exe shell.posix reactivate)" || \return
\eval "$ask_conda"
__conda_hashr
}
conda() {
\local cmd="${1-__missing__}"
case "$cmd" in
activate|deactivate)
__conda_activate "$#"
;;
install|update|upgrade|remove|uninstall)
__conda_exe "$#" || \return
__conda_reactivate
;;
*)
__conda_exe "$#"
;;
esac
}
if [ -z "${CONDA_SHLVL+x}" ]; then
\export CONDA_SHLVL=0
# In dev-mode CONDA_EXE is python.exe and on Windows
# it is in a different relative location to condabin.
if [ -n "${_CE_CONDA:+x}" ] && [ -n "${WINDIR+x}" ]; then
PATH="$(\dirname "$CONDA_EXE")/condabin${PATH:+":${PATH}"}"
else
PATH="$(\dirname "$(\dirname "$CONDA_EXE")")/condabin${PATH:+":${PATH}"}"
fi
\export PATH
# We're not allowing PS1 to be unbound. It must at least be set.
# However, we're not exporting it, which can cause problems when starting a second shell
# via a first shell (i.e. starting zsh from bash).
if [ -z "${PS1+x}" ]; then
PS1=
fi
fi

use FTP (only option) to sync files in a directory with a single line command in linux

I need to synchronize files in my computer with server to which I have only FTP access and I would prefer a single line to add to crontab which checks every day that new or updated files are transferred (overwritten).
The question has been asked years ago but no simple answer was forthcoming and I want to know if there are better solutions today than ncftput, wput etc. which do not allow to
ncftpput -R -z -u "USER" -p "PASS" webxx.at /dir/ /source/
is rumored to work, but the -z switch seems "of label" use. My experiments seem to indicate that times are not reliable checked.
Just put this code into a file FtpSync.sh and add this file into your crontab.
You can adjust the parameters in the file. I tried to create "speaking" parameters so that they explain themselves.
A call of this script will either download or upload files (depending on the parameter CopyServerdataToLocal). If you want to do both, simply start the script twice with different parameters (or create two script files).
FtpSync.sh
#!/bin/bash
# Michael Hutter, 20.11.2021
# This Script can be used to synchronize a remote FTP directory and a local directory
HOST='ftp.mywebspace.de'
USER='web1234567f1'
PASS='YourSecretPwd'
SERVERFOLDER='/FolderOnWebspace'
PCFOLDER='/home/michael/ftpsync/MyLocalFolder'
CopyMoreThanOneFileSimultaneously="--parallel=10"
CopyServerdataToLocal=1 # 0=Upload, 1=Download
IgnoreSubdirectories=1
ContinuePartiallyTransmittedFiles=0
DontOverwriteNewerExistingFiles=0 # If this is used ContinuePartiallyTransmittedFiles will not work!
DeleteAdditionalFilesInDestinationDir=0 # Deletes files in DestDir which are not present in SourceDir
RemoveSourceFilesAfterTransfer=0 # Moves the files instead of copying them
ExcludeParams='--exclude-glob .* --exclude-glob .*/' # Exclude (hidden) files and direcories -> starting with a dot
OnlyShowChangesButDontChangeFiles=0 # DryRun mode
OutputAsMuchInfoAsPossible=1 # Verbose mode
################################################################################
if [ $CopyServerdataToLocal -eq 1 ]; then
if [ $OutputAsMuchInfoAsPossible -eq 1 ]; then
echo "Modus=Download"
fi
DIRECTORIES="$SERVERFOLDER $PCFOLDER"
else
if [ $OutputAsMuchInfoAsPossible -eq 1 ]; then
echo "Modus=Upload"
fi
REVERSE='--reverse'
DIRECTORIES="$PCFOLDER $SERVERFOLDER"
fi
if [ $IgnoreSubdirectories -eq 1 ]; then
IGNORESUBDIRS='--no-recursion'
fi
if [ $ContinuePartiallyTransmittedFiles -eq 1 ]; then
CONTINUEFILES='--continue'
fi
if [ $DontOverwriteNewerExistingFiles -eq 1 ]; then
ONLYNEWER='--only-newer'
fi
if [ $DeleteAdditionalFilesInDestinationDir -eq 1 ]; then
DELETE='--delete'
fi
if [ $RemoveSourceFilesAfterTransfer -eq 1 ]; then
REMOVE='--Remove-source-files'
fi
if [ $OnlyShowChangesButDontChangeFiles -eq 1 ]; then
DRYRUN='--dry-run'
fi
if [ $OutputAsMuchInfoAsPossible -eq 1 ]; then
VERBOSE='--verbose'
fi
lftp -f "
open $HOST
user $USER $PASS
lcd $PCFOLDER
mirror $DRYRUN $REVERSE $IGNORESUBDIRS $DELETE $REMOVE $CONTINUEFILES $ONLYNEWER $CopyMoreThanOneFileSimultaneously --use-cache $ExcludeParams $VERBOSE $DIRECTORIES
bye
"

How to provide parameter in the shell script

I have below shell script where i want to create another parameter and instead of in in the line $JAVA_BIN $JAVA_OPTS --workflow test_method --config config/dbimport.$1.properties in i want to provide that parameter.
#!/bin/bash
if [[ $# -lt 1 ]]; then
echo "usage: test_method_full.sh <env> ; whereas env is one of dev|simu|prod"
exit 1
fi
# ******************** Check arguments **********
if [[ $1 != "dev" && $1 != "simu" && $1 != "prod" ]]; then
echo "env parameter has to be dev, simu or prod. Found ${1}"
exit 3
fi
# ***************** Java-Environment **************
# use given JAVA_HOME or openjava-1.8 if available
if [[ -z ${JAVA_HOME} ]]; then
# JAVA_HOME does not exist
if [[ -d /opt/java-1.8 ]]; then
JAVA_HOME=/opt/java-1.8
else
echo "JAVA_HOME could not be determined!"
exit 5
fi
fi
# set the Java binary based on JAVA_HOME
JAVA_BIN=${JAVA_HOME}/bin/java
$JAVA_BIN $JAVA_OPTS -classpath "/opt/Software/lib/*:/opt/Software/test_method/lib/*" --workflow test_method --config config/dbimport.$1.properties in
While running the script it should run like below:
test_method_full.sh simu /opt/Software/in
I dont want to hardcode /opt/Software/in/ in my shell script and make it changeable while runnig the script
You can choose to pass it as optional parameter (i.e. "${2:-/opt/Software/in/}"), which can override the default, but uses the default, if you don't pass a parameter, or use an environment variable for it, say: "${JAVA_ARG:-/opt/Software/in/}", in a similar way you are already doing it for JAVA_OPTS.

CENTOS 7 - $PATH incorrect after installing jdk

I'm new with Linux OS and I have installed jdk on centos7.
Now each time I login, I get following error message:
/usr/libexec/grepconf.sh: line 5: grep: command not found
-bash: /home/centos/.bash_profile: line 13: syntax error near unexpected token `newline'
-bash: /home/centos/.bash_profile: line 13: `export PATH=$PATH:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/usr/bin/grep>'
and all commands are "not found"
I find this post to update path:
https://unix.stackexchange.com/questions/302743/centos-7-all-command-not-found-except-cd
and I update path with this command:
PATH=/usr/local/bin:/usr/bin:bin
So now with
sudo nano /home/centos/ .bash_profile command I have following content in bash_profile file:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export PATH=$PATH:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/usr/bin/grep>
What is problem ? How can I solve the error described ?
1rst edit in order to answer #nautical questions:
Here the content of .bash_profile file :
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export PATH=$PATH:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/usr/bin/grep
Here the content of grepconf :
#!/bin/sh
case "$1" in
-c | --interactive-color)
! grep -qsi "^COLOR.*none" /etc/GREP_COLORS
;;
*)
echo >&2 "Invalid / no option passed, so far only -c | --interactive-color is supported."
exit 1
;;
esac
2nd Edit in order to answer questions in comment :
here ldd /usr/bin/grep command output:
linux-vdso.so.1 => (0x00007fff769b8000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f0454df3000)
libc.so.6 => /lib64/libc.so.6 (0x00007f0454a26000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f0454809000)
/lib64/ld-linux-x86-64.so.2 (0x000055ce09e0c000)
Here the result of ls -l /lib64/ld*
[centos#serveur-1 ~]$ ls -l /lib64/ld*
-rwxr-xr-x 1 root root 163400 Jan 29 18:55 /lib64/ld-2.17.so
lrwxrwxrwx 1 root root 10 Feb 20 21:51 /lib64/ld-linux-x86-64.so.2 -> ld-2.17.so
And each time I logout, then I login,
I get always "command not found" except for some command like for example :
java -version
So each time I must type "PATH=/usr/local/bin:/usr/bin:bin/" (answer found on this site) and each time I type echo $PATH, the output is more and more complex :
[centos#serveur-1 ~]$ echo $PATH
$PATH:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/usr/bin/grep
I suppose $PATH content is bad just after login.
So how can I solved it definitively ?
Third edit for #tripleee :
Here .bashrc file content :
[centos#serveur-1 ~]$ sudo nano /home/centos/.bashrc
GNU nano 2.3.1 File: /home/centos/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
It talks about /etc/bashrc, so this is its content:
[centos#serveur-1 ~]$ sudo nano /etc/bashrc
GNU nano 2.3.1 File: /etc/bashrc
# /etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /etc/profile
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
# are we an interactive shell?
if [ "$PS1" ]; then
if [ -z "$PROMPT_COMMAND" ]; then
case $TERM in
xterm*|vte*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
PROMPT_COMMAND="__vte_prompt_command"
else
PROMPT_COMMAND='printf "\033]0;%s#%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOM$
fi
;;
screen*)
if [ -e /etc/sysconfig/bash-prompt-screen ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
else
PROMPT_COMMAND='printf "\033k%s#%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOM$
fi
;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-de$
;;
esac
fi
# Turn on parallel history
shopt -s histappend
history -a
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u#\h \W]\\$ "
# You might want to have e.g. tty in prompt (e.g. more virtual machines)
# and console windows
# If you want to do so, just add e.g.
# if [ "$PS1" ]; then
# PS1="[\u#\h:\l \W]\\$ "
# fi
# to your custom modification shell script in /etc/profile.d/ directory
fi
if ! shopt -q login_shell ; then # We're not a login shell
# Need to redefine pathmunge, it get's undefined at the end of /etc/profile
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
# By default, we want umask to get set. This sets it for non-login shell.
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ];
then
umask 002
else
umask 022
fi
SHELL=/bin/bash
# Only display echos from profile.d scripts if we are no login shell
# and interactive - otherwise just process them to set envvars
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
fi
# vim:ts=4:sw=4
It's quite difficult to understand this mechanism when you come from "Windows world"...
Solved by updating .bash_profile as following:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/bin:/usr/bin:/bin:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin
export PATH
I'm new with Centos so I hope I will retrieve my 2 points (removed by negative vote):
I have edited my question and structured it in order to answer questions asked in comments
I have looked for answer (see link) but I don't understand all instructions so may be difficult to be clear

Bash $PS1 Trouble (ubuntu)

So I have a script in my .bashrc for customizing my prompt (see below).
function git_unpushed {
brinfo=$(git branch -v)
if [[ $brinfo =~ ("[ahead "([[:digit:]]*)]) ]]
then
echo "Not Pushed: ${BASH_REMATCH[2]}"
fi
}
function git_untracked {
untracked=$(git clean --dry-run | wc -l)
if [ $untracked -gt 0 ]
then
echo "Untracked: "$untracked
fi
}
export PS1="\
$(
# last_result=$?
uid="$(id -u)"
host="\[\e[97m\]\H"
path="\[\e[94m\]\w"
# If root
if [ "$uid" = "0" ];
then
user="\[\e[95m\]\u"
symbol="\[\e[97m\]#"
else
# If not root
user="\[\e[96m\]\u"
symbol="\[\e[97m\]\$"
fi
# If Git Repo
if [ -d './.git' ];
then
unpushed=$(git_unpushed)
untracked=$(git_untracked)
branch=$(__git_ps1)
status=$(git diff --shortstat)
second_line="hi"
else
second_line=$path
fi
echo "\[\e[1m\]$user#$host\n$second_line\n$symbol: \[\e[0m\]"
)"
My Question: Why does the path not get replaced whenever I cd to a git repo? (it does if I start a bash prompt within the repo"
I am using Ubuntu 14.04
Update:
After lot of work getting it just right, he is my result: Custom $PS1
Thanks everyone who helped out!
Edit:
As #EtanReisner points out, your code should work as intended for all users by enclosing your command substitution in single quotes.
export PS1='\
$(
# last_result=$?
uid="$(id -u)"
host="\[\e[97m\]\H"
path="\[\e[94m\]\w"
# If root
if [ "$uid" = "0" ];
then
user="\[\e[95m\]\u"
symbol="\[\e[97m\]#"
else
# If not root
user="\[\e[96m\]\u"
symbol="\[\e[97m\]\$"
fi
# If Git Repo
if [ -d "./.git" ];
then
unpushed=$(git_unpushed)
untracked=$(git_untracked)
branch=$(__git_ps1)
status=$(git diff --shortstat)
second_line="hi"
else
second_line=$path
fi
echo "\[\e[1m\]$user#$host\n$second_line\n$symbol: \[\e[0m\]"
)'
Old Answer:
This is because what you want to happen is only running every time your ~/.bashrc gets sourced. To get it to run after every command you execute, you can create a function and set the environment variable PROMPT_COMMAND to that function.
Try this:
new_ps1 (){
export PS1="\
$(
# last_result=$?
uid="$(id -u)"
host="\[\e[97m\]\H"
path="\[\e[94m\]\w"
# If root
if [ "$uid" = "0" ];
then
user="\[\e[95m\]\u"
symbol="\[\e[97m\]#"
else
# If not root
user="\[\e[96m\]\u"
symbol="\[\e[97m\]\$"
fi
# If Git Repo
if [ -d './.git' ];
then
unpushed=$(git_unpushed)
untracked=$(git_untracked)
branch=$(__git_ps1)
status=$(git diff --shortstat)
second_line="hi"
else
second_line=$path
fi
echo "\[\e[1m\]$user#$host\n$second_line\n$symbol: \[\e[0m\]"
)"
}
PROMPT_COMMAND="new_ps1"

Resources