logo
down
shadow

Check directory exists in hdfs using shell conditionals


Check directory exists in hdfs using shell conditionals

By : n.t
Date : November 18 2020, 03:01 PM
wish helps you Couple of violations (syntactic/semantic) for your initial edit.
The string in the case clause case '$table_name' in will never expand, because present under the single-quotes. It will not throw an error because you are trying to match a literal string without any expansion done. You need to double-quote it as case "$table_name" Multiple *) will never work, the case present 2nd will never match as always the first expression matches. Replace it with an actual expression
code :
if hdfs dfs -test -d /user/hive/bar/foo/$test_table; then
    printf 'table exists\n'
fi


Share : facebook icon twitter icon
How to check if a directory exists in a Bash shell script?

How to check if a directory exists in a Bash shell script?


By : Taeke
Date : March 29 2020, 07:55 AM
may help you . To check if a directory exists in a shell script you can use the following:
code :
if [ -d "$DIRECTORY" ]; then
  # Control will enter here if $DIRECTORY exists.
fi
if [ ! -d "$DIRECTORY" ]; then
  # Control will enter here if $DIRECTORY doesn't exist.
fi
ln -s "$ACTUAL_DIR" "$SYMLINK"
if [ -d "$SYMLINK" ]; then 
  rmdir "$SYMLINK" 
fi
rmdir: failed to remove `symlink': Not a directory
if [ -d "$LINK_OR_DIR" ]; then 
  if [ -L "$LINK_OR_DIR" ]; then
    # It is a symlink!
    # Symbolic link specific commands go here.
    rm "$LINK_OR_DIR"
  else
    # It's a directory!
    # Directory command goes here.
    rmdir "$LINK_OR_DIR"
  fi
fi
shell create new directory and check whether it exists

shell create new directory and check whether it exists


By : Phil
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further the file have many lines, each lines contain , Another purely shell solution:
code :
while read line; do
  set $line
  key=$1; shift
  dir=$1; shift
  test -d $dir || mkdir $dir
  mv $@ $dir
done < myfile.txt

    bll-laptop:bll$ cat t.sh
    #!/bin/bash

    cat > myfile.txt << _HERE_
    1001 d1 a b c
    1002 d2 d e f
    1003 d3 g h i
    _HERE_

    touch a b c d e f g h i
    rm -rf d1 d2 d2 > /dev/null 2>&1
    mkdir d1

    while read line; do
      set $line
      key=$1; shift
      dir=$1; shift
      test -d $dir || mkdir $dir
      mv $@ $dir
    done < myfile.txt

    ls -R

    bll-laptop:bll$ ./t.sh
    .:
    d1  d2  d3  myfile.txt  t.sh

    ./d1:
    a  b  c

    ./d2:
    d  e  f

    ./d3:
    g  h  i
    bll-laptop:bll$
how to use sshpass in shell script to check whether directory exists or not?

how to use sshpass in shell script to check whether directory exists or not?


By : Muhammad Yusuf
Date : March 29 2020, 07:55 AM
I wish did fix the issue. The square brackets in if tests are not part of the if syntax. The [ is a command of its own (also called test).
The syntax of an if statement is roughly (see Shell Grammar Rules for more if you are really curious):
code :
if <command that returns true or false>; then
    <other commands>
fi
if sshpass -p PASSWORD ssh root@192.168.16.01 '[ -d /home/test ]'; then
    echo "YES"
fi
How to check whether a file exists or not using hdfs shell commands

How to check whether a file exists or not using hdfs shell commands


By : weipinghe
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You need to be careful in the way you are detecting the job is done in this way, because there might be output before your job is completely finished.
To answer your direct question, to test for existence I typically do hadoop fs -ls $output | wc -l and then make sure the number is greater than 0.
Check if a directory exists in subdirectory in shell script

Check if a directory exists in subdirectory in shell script


By : yung gorilla
Date : March 29 2020, 07:55 AM
it helps some times That's the other way. ./ if for a directory relative to the current directory, / if for a fully specified directory, i.e.:
If you provide a full path to the directory, you need to remove the dot:
Related Posts Related Posts :
  • Using grep with pattern file to count individual pattern matches in a file
  • Why does od linenumber increment by 2?
  • How to group commands together for control operators || and &&?
  • Shell redirection: Command doesn't appear to output to stdout or stderr
  • Using dollar sign in sed for both variable replacement and character
  • Bash replace // doesn't handle anchors like Regex? Because it is glob-like
  • Escape apostrophe in docker command
  • How to skip a field in column using awk
  • bash how to quote string with quotes
  • Ansible to install Sublime Text editor in Linux
  • Ubuntu - Terminal closes when I type command?
  • Set environment variables in Docker
  • Rsync only two dictionaries
  • Bash command output as numeric variable
  • XMLStarlet remove last -n (newline) using Sed
  • Bash - Fill with 0 every number to make it 4 digits using sed
  • Create an alias of the script by calling the script with an argument: ./myscript alias
  • Propagate `set -x` in [ba]sh
  • sh script to replace all file names and folder names on mac
  • Bash script trying to compare a historical and current file and get a sum difference when lines dont match
  • Install libxcb on Windows bash subsystem
  • Make Atom CLI wait for file to be closed
  • In bash, cp does copy dot files while using wildcard? Which option should I use
  • how to substitute and print column in perl just like in awk
  • find -exec when used with sed for file rename not working
  • How to check if a file's size is greater than a certain value in Bash
  • How can I auto increment file name version in a bash shell environment?
  • shuf command isn't random inside of find -exec?
  • A way to push terminal prompt to top of screen without deleting history
  • Bash - Break out of loop with Ctrl-C but continue with script
  • Passing Scripts as Arguments Bash
  • How to automate curl POST for CSV file?
  • Bash substitution inside substitution
  • Print awk output on the same line
  • Bash: how to get the complete substring of a match in a string?
  • SCP username with colon
  • SSH command chain does not work when put in single line
  • Bash: split long string argument to multiple lines?
  • Unix Bash Script - command not found
  • Splitting a large, complex one column file into several columns with awk
  • How to compare two dates of different format?
  • Split string with | character in Bash and export environment variables from first row
  • AWK if else condition not printing correctly
  • Parallel processes in bash, kill with Ctrl C
  • how to move files inside folders in one folder
  • Storing multiple arguments in a string with quotes in shell
  • Bash complete with "@"-sign
  • Problem with comparing numerical values while column-wise parsing CSV file
  • How to reuse a variable in shell script when used in curl?
  • Add to $PATH with Shell Script
  • Check if network drive is mounted, if not send e-mail and try to mount
  • Getting an exit status stored to a variable inside an ssh command
  • Shortcut for opening tmux terminal
  • Can not overwrite folder from source to destination
  • Trickle FTP connection
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org